If you don't want the blank line, then remove or comment out the line just before the Next statement. (The source document is whatever document was active when you ran the macro.) The macro places a blank line between each table in the Target document. The macro, once run, creates a brand-new document (Target) and copies the tables from the original document (Source) into the new one. In the WORD document, go to the desired location. That means you can step through each item in the collection (each item will be an individual table) and then copy it. In Excel, select the range of cells from the worksheet (for example, A1 to K60) press Ctrl+C to copy. Fortunately, all the tables in a document are made available to VBA through the Tables collection. The easiest way to do this type of copying is by using a macro. Sub CreateWordFile () Dim oWord As Object ' DECLARE OBJECT Set oWord CreateObject (Class:'Word.Application') ' INITIALIZE THE OBJECT. Let’s write the entire code in a procedure. This could be helpful if you have tabular information that needs to be available in the new document, but you don't need the rest of the information from the original document. So, now you know how to create a new Word document from Excel using VBA. If you do a lot of work with tables, you may (at some point) want to copy all the tables from one document to a brand-new document. Here is the relevant code: For Each ws In. At that point, the Word table pastes beneath the copied Word table. There is no problem until I try to paste into Excel. I need to copy the Word tables back into the Excel file on a newly created sheet. These correspond with Excel worksheet names. An alternative option would be to copy the last table from the word file. The top row (header) of the table I need is always the same in all files and I think this will be a good way to to identify the table. Sub ImportWordTable () Dim wdDoc As Object Dim wdFileName As Variant Dim TableNo As Integer table number in Word Dim iRow As Long row index in Excel Dim iCol. Hello, I would like to create a macro that when copies a table (with a specific heafer) from a Word file into an Excel worksheet. It prompts you for the word document as well as the table number if Word contains more than one table. In fact, I've seen some documents that consist almost entirely of tables. I have a Word file that contains bookmarked tables. Here is some code that reads a table from Word into the active worksheet of Excel. Tables are a great way to present many types of information.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |