Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place text in the clipboard so that it pastes as a table in Word?

Using VBA in MS Office, how do I add text to the Windows clipboard so that it will paste into Word as a table?

like image 474
Shane Miskin Avatar asked Nov 17 '08 22:11

Shane Miskin


People also ask

How do I paste text from Clipboard in Word?

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.

How do I copy and paste a table format in Word?

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.


1 Answers

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.

like image 102
Kluge Avatar answered Sep 20 '22 23:09

Kluge