king8462 发表于 2016-8-20 20:49:51

[已解决]求助高手把替换word页眉的vba转换成au3代码

本帖最后由 king8462 于 2016-8-20 21:50 编辑

VBA如下:
Sub cs()
Set myRange = ActiveDocument.Sections(1).Headers(2).Range
myRange.Find.Execute findtext:="1zyhao", replacewith:="2016", Replace:=wdReplaceAll
End Sub

king8462 发表于 2016-8-20 21:49:28

自己解决了,代码如下:

#include <Word.au3>
Global $word = ObjCreate("word.application")
$word.visible = True
$Doc =$Word.documents.open (@DesktopDir & "\0001.doc")
Local $context = "1zyhao"
Local $newcontext = "2016"
$Doc.PageSetup.HeaderDistance
$Word.ActiveWindow.ActivePane.View.SeekView = 2
Sleep(100)
With $doc.Application.Selection.range.Find
.ClearFormatting ()
.Replacement.ClearFormatting ()
.Execute($context,0,0,0,0,0,1,1,0,$newcontext,2)
EndWith

pigWoWo 发表于 2017-8-23 15:17:52

大神,
不行啊,只能替换内容,不能替换 页眉 呀

king8462 发表于 2017-8-23 15:36:59

回复 3# pigWoWo

修改下这行代码
    $Word.ActiveWindow.ActivePane.View.SeekView = 1

king8462 发表于 2017-8-23 15:40:49

回复 3# pigWoWo

如果替换页脚,修改7、8行代码如下:
$Doc.PageSetup.footerDistance
$Word.ActiveWindow.ActivePane.View.SeekView = 10

pigWoWo 发表于 2017-8-26 01:35:44

可以了 ,膜拜
页: [1]
查看完整版本: [已解决]求助高手把替换word页眉的vba转换成au3代码