Sub
GetFormData()
Application.ScreenUpdating =
False
Dim
wdApp
As
New
Word.Application
Dim
wdDoc
As
Word.Document
Dim
FmFld
As
Word.FormField
Dim
CCtrl
As
Word.ContentControl
Dim
strFolder
As
String
Dim
strFile
As
String
Dim
WKSht
As
Worksheet, i
As
Long
, j
As
Long
strFolder = Getfolder
If
strFolder =
""
Then
Exit
Sub
Set
WKSht = ActiveSheet
i = WKSht.Cells(WKSht.Rows.Count, 1).
End
(xlUp).Row
strFile = Dir(strFolder &
"\*.docx"
, vbNormal)
While
strFile <>
""
i = i + 1
Set
wdDoc = wdApp.Documents.Open(Filename:=strFolder & "\" & strFile, AddToRecentfiles:=
False
, Visible:=
False
)
With
wdDoc
j = 0
For
Each
FmField
In
.FormFldFields
j = j + 1
WKSht.Cells(i, j) = FmFld.Result
Next
End
With
wdDoc.Close SaveChanges:=
False
strFile = Dir()
Wend
wdApp.Quit
Set
wd.Doc =
Nothing
:
Set
wdApp =
Nothing
:
Set
WKSht =
Nothing
Application.ScreenUpdating =
True
End
Sub
Function
Getfolder()
As
String
Dim
oFolder
As
Object
Getfolder =
""
Set
oFolder = CreateObject(
"Shell.Application"
).BrowseForFolder(0,
"Choose a folder "
, 0)
If
(
Not
oFolder
Is
Nothing
)
Then
Getfolder = oFolder.Items.Item.Path
Set
oFolder =
Nothing
End
Function