#16
|
||||
|
||||
Try the following Excel macro:
Code:
Sub GetWordTableData() 'Note: this code requires a reference to the Word object model Application.ScreenUpdating = False Dim wdApp As New Word.Application Dim wdDoc As Word.Document Dim wdTbl As Word.Table Dim wdRng As Word.Range Dim strFolder As String, strFile As String Dim WkSht As Worksheet, i As Long, j As Long strFolder = GetFolder If strFolder = "" Then Exit Sub Set WkSht = ActiveSheet i = WkSht.Cells(WkSht.Rows.Count, 1).End(xlUp).Row strFile = Dir(strFolder & "\*.docx", vbNormal) While strFile <> "" i = i + 1 Set wdDoc = wdApp.Documents.Open(Filename:=strFolder & "\" & strFile, _ AddToRecentFiles:=False, Visible:=False) With wdDoc For j = 1 To 3 With .Tables(1) Set wdRng = .Cell(2, j).Range With wdRng .End = .End - 1 WkSht.Cells(i, j).Value = .Text End With End With With .Tables(2) Set wdRng = .Cell(2, j).Range With wdRng .End = .End - 1 WkSht.Cells(i, j + 3).Value = .Text End With End With Next End With wdDoc.Close SaveChanges:=False strFile = Dir() Wend wdApp.Quit Set wdDoc = Nothing: Set wdApp = Nothing: Set WkSht = Nothing Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#17
|
|||
|
|||
Hi macropod,
Thank you for the code. I will have a good go at it - will need some time to digest them. Just a few more questions which I hope you could help me with, please: - Your GetWordTableData uses sub instead of function - from my understanding, to return a value we need to use function. Is it not so? Thank you. |
#18
|
||||
|
||||
Be assured, I know how to code... The code doesn't merely return a value, it does something with a whole series of values.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#19
|
|||
|
|||
Works like a charm! Thank you very much... Now i need to understand what you have done.
p/s: I have no doubt about the code. It's just for my own learning that I am asking the question. Thank you! |
Tags |
copy/paste, multiple files, words |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Copy Excel data into an existing Word Table | JJG | Word | 1 | 12-18-2013 05:41 PM |
How to Copy data from Outlook mail and Paste it in a Excel sheet? | padhu1989 | Outlook | 0 | 09-11-2012 04:07 AM |
how to copy all ms word tables into excel | rehan129 | Word | 0 | 01-28-2012 10:17 AM |
How to copy automatically data from Excel file to Word file? | fuchsd | Word | 6 | 10-25-2011 05:52 AM |
Copy all comments & cell contents (i.e. data) to word? | IanM | Excel | 0 | 07-03-2010 11:14 PM |