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
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>