我有一个模板,它有一个包含图片标题的页面。我想将这些图像复制到我的ActiveDocument。我正在使用下面的代码:从模板复制/粘贴标题
Set doc = ActiveDocument
strTemplate = "C:\Users\rajtilak\Desktop\Report.dotx"
Set docTemplate = Documents.Open(strTemplate)
Set hdr1 = docTemplate.Sections(1).headers(wdHeaderFooterPrimary)
Set hdr2 = doc.Sections(3).headers(wdHeaderFooterPrimary)
hdr1.Range.Copy
hdr2.Range.PasteAndFormat wdFormatOriginalFormatting
docTemplate.Close False
这工作正常,但它不是从模板的第1部分,但第5部分复制标题。有没有其他方法使用VBA从Word文件中复制标题?
如果将'hdr1'设置为与[此列表(MSDN)]不同类型的标头,那么该怎么办?(https://msdn.microsoft.com/zh-cn/vba/word-vba/articles/wdheaderfooterindex-enumeration -字)。 –
它的工作!所以我做的是,我从中复制标题的模板,因为我从中复制的页面,我将代码更改为: 设置hdr1 = docTemplate.Sections(1).headers(wdHeaderFooterFirstPage) 其余的,我将代码更改为: 设置hdr2 = doc.Sections(3).headers(wdHeaderFooterPrimary) 它工作。 – rajb