Assuming all the form fields are text fields, put all the form documents in
a folder (with no other documents) and run the following macro. If there are
dropdown fields and checkbox fields, you will need to modify the definition
of sText currently:
sText = oDoc.FormFields(i).Result
to accommodate the different types of fields.
Sub ExtractFormData()
Dim oDoc As Word.Document
Dim oTarget As Word.Document
Dim iCol As Integer
Dim i As Long
Dim sText As String
Dim DocList As String
Dim DocDir As String
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder containing the forms click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
DocDir = fDialog.SelectedItems.Item(1)
If Right(DocDir, 1) <> "\" Then DocDir = DocDir + "\"
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
Set oTarget = Documents.Add
Application.ScreenUpdating = False
DocList = Dir$(DocDir & "*.doc")
Do While DocList <> ""
Set oDoc = Documents.Open(DocDir & DocList)
iCol = oDoc.FormFields.Count
For i = 1 To iCol
sText = oDoc.FormFields(i).Result
If oTarget.Tables.Count = 0 Then
oTarget.Tables.Add oTarget.Range, 1, iCol
End If
With oTarget.Tables(1).Cell(iCol, i).Range
.Text = sText
.Collapse wdCollapseEnd
End With
Next i
oTarget.Tables(1).Rows.Add
oDoc.Close SaveChanges:=wdDoNotSaveChanges
DocList = Dir$()
Loop
Application.ScreenUpdating = True
End Sub
http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>