Read Text Form Fields from Word Documents

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all,

Is it possible to read all forms control objects from a Word document and
then put them into the columns? For example:

In the Word document:
Name: Text1 (Text Form Field 1)
Date of Birth: Text2 (Text Form Field 2)
Gender: Dropdown1 (Drop-down Field 1)
Click here if you accept the agreement: | | (Check box field 1)

Then put the above fields into the spreadsheet like:
Column A: Text1
Column B: Text2
Column C: Dropdown1
Column D: Check1

Appreciate if you have any idea. Thanks in advance!

Florence
 
Hi Florence,
Is it possible to read all forms control objects from a Word document and
then put them into the columns?

sure.

Sub Test444()
' early binding. Word already running
' doc in question is active document
Dim oWrd As Word.Application
Dim oDcm As Word.Document
Dim oFld As Word.FormField
Dim c As Long ' column
Dim r As Long ' row
r = 1
c = 1
Set oWrd = GetObject(, "Word.application")
oWrd.Visible = True
Set oDcm = oWrd.ActiveDocument
For Each oFld In oDcm.FormFields
ActiveSheet.Cells(r, c).Formula = oFld.Result
' or
ActiveSheet.Cells(r, c).Value = oFld.Result
' Excel experts may tell you about the difference
r = r + 1
Next
' some more code, possibly, for closing etc
' and to make sure the created objects are
' removed from memory, destroyed, so to say
End Sub


HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
Hi,

Yes this is possible. You must be having a 'SUBMIT' or 'SAVE' button on the
Word form. use the bleow logic for the click event of this button-

Create an instance of Excel object
Cretae an instance of Workbook object
Open your workbook with window hidden
Activate your desired worksheet
check for the last row on this worksheet
update the details on this worksheet
close the workbook with saving

Regards,
Pranav Vaidya
 
Back
Top