excel - 让我的 Word 模板出现在每个新页面上
问题描述
现在我使用代码来填写一份文件:
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
解决方案
推荐阅读
- javascript - 在我达到 5 之前无法让我的脚本打印随机数
- arrays - 访问 flatlist 上的 redux 存储数组值反应原生
- kotlin - 为 jooq 生成的所有类插入注释
- java - CoreNLP:找出一个词是单数还是复数
- cassandra - 配置写入多副本时,Cassandra 是否使用两阶段提交?
- javascript - 当输入元素处于活动状态时如何禁用选择字段?
- node.js - 使用 mongoose 中的另一个集合数组填充数据
- networking - 在 Vagrant VM 上禁用互联网(外部访问)
- javascript - Chrome扩展程序无需单击图标即可开始工作?
- c++ - 在另一个线程中调用 luaL_error 会引发 qWarning