Hi, I am fairly new to VBA so I have been searching thoughthis forum for examples. There seem to be plenty of similar macros butnothing suitable.
What I am trying to do is to match data at the top of theworkbook in a range of tables in multiple word files. Then pull the information in the cell to theright into the workbook in the appropriate cell.
I am using 2010 edition of both excel and word, I have attached a sample file with tables that I am trying to pull information from. Any from "Product Name", "Reference Code", "Stones" and "Contains Gluten?"
The following code worked to pull information from contentcontrolled sections of a word file (from a table). I have been unable to workthis for non content controlled though
[VBA]Sub GetFormData()
'Note: this coderequires a reference to the Word object model
Application.ScreenUpdating = False
Dim wdApp As NewWord.Application
Dim wdDoc AsWord.Document
Dim CCtrl AsWord.ContentControl
Dim strFolder AsString, strFile As String
Dim WkSht AsWorksheet, 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
j = 0
For EachCCtrl In .ContentControls
j = j + 1
WkSht.Cells(i, j) = CCtrl.Range.Text
Next
End With
wdDoc.CloseSaveChanges:=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 AsObject
GetFolder =""
Set oFolder =CreateObject("Shell.Application").BrowseForFolder(0, "Choose afolder", 0)
If (Not oFolder IsNothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder =Nothing
End Function[/VBA]
Any help would be greatly appreciated, thanks
Stephen