The following code works, but I need to tweak this to do the following.
1.Word documents that are in folder are protected w/o password, need this macro to unprotect and then retrieve data.
2. Would like macro to be able to retrieve a form field by bookmark name
instead of all form fields.
Any help would be appreciated.
Code:
Dim mydoc As Document
Dim target As Document
Dim i As Long
'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() <> -1 Then Exit Sub
MyPath = .Directory
End With
'strip quotation marks from path
Set target = Documents.Add
If Len(MyPath) = 0 Then Exit Sub
If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If
'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
Set mydoc = Documents.Open(MyPath & MyName)
For i = 1 To mydoc.FormFields.Count - 1
target.Range.InsertAfter mydoc.FormFields(i).Result & vbTab
Next i
target.Range.InsertAfter mydoc.FormFields(i).Result & vbCr
mydoc.Close wdDoNotSaveChanges
MyName = Dir$
Loop