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
标签:ThisWorkbook,VB,documents,word,Sub,wordapp,Set,页眉,End 来源: https://www.cnblogs.com/rn-05181226-rw/p/11721252.html