VB 替换word文档中页眉页脚的文字

Posted rn-05181226-rw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB 替换word文档中页眉页脚的文字相关的知识,希望对你有一定的参考价值。

查找资料,替换成功的只有替换页面内容的文字

Sub docs()Dim wordapp
  Set wordapp = CreateObject("Word.Application")
    With wordapp
        .documents.Open (ThisWorkbook.Path & "test.docx")
        .Visible = True
        .activedocument.content.Find.Execute FindText:=text1, ReplaceWith:=text2, Replace:=2
        .documents.Close
    End With
  wordapp.Quit
  Set wordapp = Nothing
End Sub

加上写C#用过DOM API 测试成功

Sub docs()
Dim wordapp
  Set wordapp = CreateObject("Word.Application")
    With wordapp
        .documents.Open (ThisWorkbook.Path & "test.docx")
        .Visible = True
        .ActiveWindow.ActivePane.View.SeekView = 9
        .Selection.Find.Execute FindText:="visit_name", ReplaceWith:=Sheet1.Cells(1, i).Value, Replace:=2
        .ActiveWindow.ActivePane.View.SeekView = 0
        .documents.Close
    End With
  wordapp.Quit
  Set wordapp = Nothing
End Sub  

 

以上是关于VB 替换word文档中页眉页脚的文字的主要内容,如果未能解决你的问题,请参考以下文章