现在我使用代码填充一个文档:
Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document
strFile = Dir(strFolder & "\*.docx", vbNormal)
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
.Bookmarks.Item("Company_Name").Range.InsertAfter Prefix & " " & Company_Name
.Bookmarks.Item("Company_Street").Range.InsertAfter Company_Street
.Bookmarks.Item("Company_Street_Nr").Range.InsertAfter Company_Street_Nr
.Bookmarks.Item("Company_PostCode").Range.InsertAfter Company_PostCode
.Bookmarks.Item("Company_City").Range.InsertAfter Company_City
.Bookmarks.Item("Company_Country").Range.InsertAfter Company_Country
' here need to do the same thing from 1 to 100 times again, but with other data
.Close SaveChanges:=True
End With
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
但是如何在相同的打开实例中再次使用此模板,那么在填充第一个书签之后,在与下一页相同的文档中创建新的相同模板,然后再次填充它们?
所以我需要类似的东西
Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document
strFile = Dir(strFolder & "\*.docx", vbNormal)
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
fillbookmarks ' with new data
add new page from the same strFile
fillbookmarks ' with new data
add new page from the same strFile
fillbookmarks ' with new data
.Close SaveChanges:=True
End With
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub