View Single Post
 
Old 01-09-2014, 12:00 AM
RonNCmale RonNCmale is offline Windows 7 64bit Office 2003
Novice
 
Join Date: Sep 2012
Posts: 15
RonNCmale is on a distinguished road
Default

Yes, I actually named it MyField to test

On the word template I have a text formfield that for the bookmark name; I named it "MyField".

Code:
Sub ProcessDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdSrcDoc As Document, wdTgtDoc As Document
Dim StrFlds As String, i As Long
StrFlds = "Form1,Form2,Form3"
strFolder = GetFolder
If strFolder = "" Then Exit Sub
Set wdTgtDoc = ActiveDocument
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  Set wdSrcDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
  With wdSrcDoc
    wdTgtDoc.Range.InsertAfter .FormFields("MyField").Result & vbCr
    .Close SaveChanges:=False
  End With
  strFile = Dir()
Wend
Set wdSrcDoc = Nothing: Set wdTgtDoc = 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
I get a runtime error 5941 The requested member of the collection does not exist on

wdTgtDoc.Range.InsertAfter .FormFields("MyField").Result & vbCr

Form1, Form2, and Form3 need to be in paragraph form in sequential order on the target document
Reply With Quote