How do I save data from a Word 2007 form with non-legacy controls

L

L McDowell

I have tried checking the 'save form data as delimited text file' box under
'preserve fidelity when sharing this document' but it doesn't work. I gather
from web browsing that it only works for data collected with legacy controls.
I am not a developer, so how else can I get the form input data into a text
delimited file for use in Access or Excel?
 
G

Graham Mayor

You can do it with a different approach eg. The following macro based on the
code from my web site for exttacting data from legacy form fields will
extract the text content from Word 2007 content controls in a batch of forms
and add them to a comma delimited text file which you can load into Excel
(and Access). The original forms are unaffected.

Sub ExtractDataFromContentControls()
Dim DocList As String
Dim DocDir As String
Dim objCC As Range
Dim oForm As Document
Dim TargetDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
On Error GoTo err_FolderContents
With fDialog
.title = "Select Folder containing the completed form documents and
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
Application.ScreenUpdating = False
DocList = Dir$(DocDir & "*.docx")
Set TargetDoc = Documents.Add
TargetDoc.SaveAs FileName:="DataDoc.txt", _
FileFormat:=wdFormatText
Do While DocList <> ""
WordBasic.DisableAutoMacros 1
Set oForm = Documents.Open(DocDir & DocList)
With oForm
For i = 1 To .ContentControls.Count
Set objCC = .ContentControls(i).Range
TargetDoc.Range.InsertAfter objCC
If i <> .ContentControls.Count Then
TargetDoc.Range.InsertAfter ", "
End If
Next i
TargetDoc.Range.InsertAfter vbCr
End With
oForm.Close SaveChanges:=wdDoNotSaveChanges
TargetDoc.Save
DocList = Dir$()
WordBasic.DisableAutoMacros 0
Loop
Application.ScreenUpdating = True
Exit Sub
err_FolderContents:
MsgBox Err.Description
WordBasic.DisableAutoMacros 0
End Sub


http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
L

L McDowell

Graham, thank you very much for taking the time to reply and sharing this
code. Unfortunately, I am not a developer so I really don't know what to do
with it. I'm hoping to find a solution that doesn't require the use of code.
But your response is appreciated.
 
G

Graham Mayor

Install the macro - http://www.gmayor.com/installing_macro.htm
Put all the forms from which you wish to extract the data in a separate
folder.
Run the macro.
Pick the folder containing the forms from the macro dialog.
The forms are all processed and the results saved in the same folder in a
comma delimited text file 'DataDoc.txt' which is compatible with
Excel/Access.
I cannot imagine any means of extracting data from forms to Excel/Access
that doesn't use code.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
B

Beth Melton

This isn't a Word solution but if you have Access 2007 you can use Collect
via E-mail to generate an HTML form and send by e-mail and collect your data
directly in an Access table. The wizard will step you through the process,
send the e-mails, and you can elect to update your Access table
automatically upon receipt of the returned emailed form. Note you need to
use Outlook 2007 to send the and receive the emailed forms but the
recipients don't need to use Outlook 2007.

~Beth Melton
Microsoft Office MVP
 
L

L McDowell

Beth, thanks much for your suggestion. That is what I should have done from
the beginning. However, I already created my form in Word and have been
getting back completed forms. It never occurred to me that I would not be
able to retrieve the information entered into the controls. I'm afraid I'm
still stumped.
 
G

Graham Mayor

The macro that I posted on the 10th, with further explanation how to both
install it and use it should allow you to recover the data from your forms.
However if it does not work for you (and as all the returned forms will
probably have the same file name that may prove a problem) , send me a
completed form (with sample data) to the link on the home page of my web
site and I will see where the problem lies.

Though much of it may be over your head, see Processing Forms Received by
E-Mail at http://www.gmayor.com/ExtractDataFromForms.htm . That version is
aimed at legacy forms, but it can be altered to work with content controls,
if it interests you. It simply reads the attachments from the e-mail
messages in an Outlook folder and adds the field data to a comma delimited
file or Word table.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
L

L McDowell

Hi Graham,
Thank you for sticking with me on this. I have gone through the steps for
installing your macro in Word, including adding the module in Normal. One of
the problems I encountered was pasting the code into the module. There was a
section in red with a misplaced line break from the way it was pasted. When I
place the cursor in front of it and backspace, I get this error:
Compile error: Expected: end of statement
I haven't yet gotten to the point of trying the macro. Do you have
suggestions for how to deal with this error? Thanks again,
Laurie
 
G

Graham Mayor

Which of the macros are you testing and what was the section in red? The
macros should paste directly from the web page into the macro editor without
unwanted line breaks.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
L

L McDowell

I was copying it from an email sent to our IT dept. I went back to the web
and copied from there. Seems fine. Many thanks.
 
L

L McDowell

Graham, I corrected the macro text and gave it a test run. It is miraculous
to me. Problems I'm having seem to do with how the users used the template
but the macro itself seems to work like a charm. I don't completely
understand it but I am very grateful. Thanks a million!
 

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