How export data in a word “text form field†into excel spreadshee

S

Steve Jones

I have created a Word template and would like to capture the data in the text
form fields by importing it into excel spreadsheet. How do I do that with
out retyping it in?

What discussion group would be the best to post this question to?
 
G

Greg Maxey

Steve,

I am just dipping my toes in the water leaning to connect Word data to
Excel. Something like this might work where the sample form has three
fields per record. Change "C" according to the number of fields you will
use. The first row of the spreadsheet is for the column headings.

Sub ExportToExcel()
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim myWB As String
Dim oFF As FormField
Dim i As Long
myWB = "C:\myExportBook1.xls"
Set oXL = New Excel.Application
On Error GoTo Err_Handler
Set oWB = oXL.Workbooks.Open(FileName:=myWB)
Set oSheet = oWB.Sheets("Sheet1")
Dim LastRow As Long
LastRow = oSheet.Cells(oSheet.Rows.Count, "C").End(xlUp).Row
i = 1
For Each oFF In ActiveDocument.FormFields
oSheet.Cells(LastRow + 1, i).Value = oFF.Result
i = i + 1
Next oFF
oWB.Save
Set oSheet = Nothing
Set oWB = Nothing
oXL.Quit 'Added
Set oXL = Nothing
'Excel.Application.Quit
Exit Sub
Err_Handler:
MsgBox myWB & " caused a problem. " & Err.Description, vbCritical,
"Error: " _
& Err.Number
End Sub
 
H

Helmut Weber

Hi Steve,

see the posting above:
"Send data from Word to Excel"

Instead of the bookmarks-section
use something like this:

Dim oFld As FormField
For Each oFld In ActiveDocument.range.FormFields
If oFld.Type = wdFieldFormTextInput Then
MsgBox oFld.Result ' for testing
End If
Next
What discussion group would be the best to post this question to?

I don't think there is an Excel-Word group
or a Word-Excel group. So for special challenges
you might have to ask here or in other Word-groups,
or in the different Excel-groups.

Though putting text from textformfields
into an Excel-workbook is no challenge.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

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

Top