
In this article, we will focus on moving data from excel to word document. We all transfer data from excel to word manually which becomes tedious sometimes when it comes to performing the same steps too many times in a day in order to avoid the manual steps, we will write VBA code to do all the steps. However, excel data can be copied & pasted into word & then saved as word document. Word application cannot open excel files directly. In excel, there is no such feature that could allow you to convert the data from excel workbook to word file. WdFileName = Application.GetOpenFilename("Word files (*.docx),*.docx",, _Ĭells(resultRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.If you are required to copy & paste data from multiple excel worksheets into MS Word then you should read this article. Thank you so much Damon and modified it to open docx files, moved a worksheet clear line after checking for escape by user. Next trick: working out how to extract a table within a table from Word. "Enter the table to start from", "Import Word Table", "1")Ĭells(resultRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text) TableNo = InputBox("This Word document contains " & tableNo & " tables." & vbCrLf & _ I changed this one with an addition to loop through all tables (starting from the chosen table): Option Explicitĭim tableNo As Integer 'table number in Word But for now I am hoping it is all one continuous table and will not require any modification. If your document contains many tables, as would be the case if your 100+ page table is actually a separate table on each page, this code could easily be modified to read all the tables. Run the macro from the Excel interface as you would any other (Alt-TMM). To do this, go to the VBA (keyboard Alt-TMV), insert a macro module (Alt-IM), and paste the code into the code pane. This macro should be inserted into Excel (not Word) and put into a standard macro module rather than into the worksheet or workbook event code modules. 'copy cell contents from Word table cells to Excel cellsĬells(iRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text) "Enter table number of table to import", "Import Word Table", "1") TableNo = InputBox("This Word document contains " & TableNo & " tables." & vbCrLf & _

MsgBox "This document contains no tables", _ Set wdDoc = GetObject(wdFileName) 'open Word file If wdFileName = False Then Exit Sub '(user cancelled import file browser)

"Browse for file containing table to be imported") WdFileName = Application.GetOpenFilename("Word files (*.doc),*.doc",, _ Sub ImportWordTable()ĭim TableNo As Integer 'table number in Wordĭim iCol As Integer 'column index in Excel It prompts you for the word document as well as the table number if Word contains more than one table. Here is some code that reads a table from Word into the active worksheet of Excel.
