【发布时间】:2019-12-03 00:23:07
【问题描述】:
我正在编写一个 VB.net 应用程序,它采用 Word 文档作为模板,并在文档中查找和替换多个标签。我可以很好地为正文文本执行此操作,但我无法使其适用于文档页脚中的文本。我怎样才能做到这一点?
Imports Microsoft.Office.Interop
Dim oWord As Word.Application
Dim oDoc As Word.Document
Public Sub Create_Report()
Dim clientName As String = InputBox("Enter the [Client Contact's Name] for the report:")
Dim empName As String = InputBox("Enter the [Employee's Name] for the report:")
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add("template.dotx")
ReplaceTemplateText("<<<Contact>>>", clientName)
ReplaceTemplateText("<<<Employee>>>", empName )
oDoc.SaveAs("report.docx")
oDoc.Close()
oWord.Quit()
MsgBox("Report Complete", MsgBoxStyle.OkOnly)
End Sub
Public Sub ReplaceTemplateText(findWord As String, replaceWord As String)
'Replace text in the Template document with input text
'Body
oDoc.Content.Find.Execute(FindText:=findWord, ReplaceWith:=replaceWord, Replace:=Word.WdReplace.wdReplaceAll)
'Footer
???
End Sub
【问题讨论】:
-
由于您对 Stack Overflow 相当缺乏经验:通常单击回答问题的贡献旁边的复选标记。这为寻求类似问题帮助的其他人提供了有用的信息,告诉那些回答问题的人已经解决了问题......并向回答者奖励“积分”。获得足够积分后,您还可以对任何您认为有帮助的贡献(问题或答案)进行投票,这有助于问答存储库引导人们寻找有用的信息。
-
没问题 :-) 在某些时候我们都是!
标签: vb.net search ms-word footer document