How to Paste Excel Data into Visio Using VBA
Question details
The user needs to know the exact VBA code and method required to paste a copied range of Excel data into a Microsoft Visio document.

- Product
- Microsoft Excel, Microsoft Visio
- Device & OS
- not provided
- Scenario
- Automating the transfer of spreadsheet data from Excel to a Visio diagram page using macro code.
- Observed behavior
- Requires the correct PasteSpecial method parameters to successfully paste the clipboard contents as an Excel Worksheet object within Visio.
Ensure you have copied the target data range in Excel to your clipboard and that your Visio VBA environment is open and ready to execute macros.
Use the Visio Page PasteSpecial Method in VBA
Utilize the PasteSpecial method within Visio VBA with the specific format code for an Excel Worksheet to paste your copied data.
To paste Excel data into Visio programmatically, you must invoke the PasteSpecial method on a Visio Page object. The format code determines how the clipboard data is interpreted. For an Excel worksheet, the format code is typically 49162, though you can verify this by recording a manual paste operation in Visio.
Select the required range of cells in your Excel workbook and copy it to the clipboard.
In your Visio VBA editor, declare your variables using specific object types (e.g., Dim visPage As Visio.Page) rather than generic objects. This enables VBA IntelliSense and makes coding easier.
Use the PasteSpecial method on your target page object. For example, run the code: visPage.PasteSpecial 49162, False, False. The value 49162 instructs Visio to paste the data as an Excel Worksheet format.

Manage Spreadsheets Seamlessly with WPS Office
While Visio VBA operations are specific to the Microsoft Office environment, WPS Office offers a free, lightweight, and highly capable alternative for all your spreadsheet, document, and presentation needs. Enjoy advanced data analysis tools with zero learning curve.
- 1. Download WPS Office: Visit the official WPS Office website and download the free installation package for your operating system.
- 2. Install and Launch: Follow the on-screen installation steps. Once installed, open WPS Spreadsheet to start managing your data.
- 3. Open Your Excel Files: Directly open any existing .xlsx or .xls files without needing any format conversion. Your original formatting remains perfectly intact.

Frequently Asked Questions
How do I find the correct PasteSpecial format code for other applications in Visio?
You can discover the exact format code by utilizing the Macro Recorder in Visio. Start recording a new macro, manually perform 'Paste Special' choosing the desired format, stop the recording, and then inspect the generated VBA code to identify the format number used.
Why is VBA IntelliSense not working for my Visio objects?
IntelliSense may fail to load if you are using late binding (e.g., declaring variables simply as 'Object'). Ensure you declare your variables with specific Visio object types, such as Visio.Application, Visio.Document, and Visio.Page.
Can I fully automate both copying from Excel and pasting to Visio in one script?
Yes. By adding a reference to the 'Microsoft Excel Object Library' via 'Tools > References' in the Visio VBA editor, you can programmatically open an Excel workbook, copy a specific range, and paste it into Visio all within a single macro.




