Using VBA in MS Office, how do I add text to the Windows clipboard so that it will paste into Word as a table?
In your document, click where you want to paste the item. Do one of the following in the Clipboard: Click the down arrow next to the item you want to paste, and click Paste. To paste everything in the Clipboard to the selected area in your document, click Paste All.
Press Ctrl + C (Windows) or ⌘ Cmd + C (Mac). This will copy the table and it's information. With this table in your clipboard, you can paste it anywhere, but the formatting may not remain if you paste it into a non-Word document like Notepad.
The Windows clipboard supports multiple formats. When you want to place things in the clipboard, you make one or more calls to RegisterClipboardFormat() telling it the formats of the objects you will be placing on the clipboard, followed by calls to SetClipboardData() which actually places the data into the clipboard.
If you want to be able to paste a Table into Word, then HTML is the easiest format to work with. Just copy an HTML table onto the clipboard, and it will paste correctly into Word, provided that you first register the clipboard data as an HTML object.
I'd give you some code, but it's easiest to just reference an example on MSDN:
How to add HTML code to the clipboard using Visual Basic
This page even shows an example of copying an HTML table onto the clipboard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With