View Single Post
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default How do I save data from a Word 2007 form with non-legacy controls

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
Word MVP web site http://word.mvps.org




L McDowell wrote:
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?