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  

 

上一篇:剑指offer——59二叉搜索树的第k大节点


下一篇:LeetCode Hot 100 No.105 从前序与中序遍历序列构造二叉树