Word

  • Thread starter Thread starter Annette
  • Start date Start date
A

Annette

I am needing to create a table. From forms that will be sent to me. The forms
are Word templetes with fillabe fields. Once I received the form I will need
to enter the information into a table. I would like to do all this in Word.
can it be done? would I use a mail merge? I not familar with mail merges. I
know how to export the information to EXCEL but would perfer to keep all this
in Word.
 
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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top