找回密码
 加入
搜索
查看: 2092|回复: 5

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

[复制链接]
发表于 2016-8-20 20:49:51 | 显示全部楼层 |阅读模式
本帖最后由 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
 楼主| 发表于 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
发表于 2017-8-23 15:17:52 | 显示全部楼层
大神,
不行啊,只能替换内容,不能替换 页眉 呀
 楼主| 发表于 2017-8-23 15:36:59 | 显示全部楼层
回复 3# pigWoWo

修改下这行代码
    $Word.ActiveWindow.ActivePane.View.SeekView = 1
 楼主| 发表于 2017-8-23 15:40:49 | 显示全部楼层
回复 3# pigWoWo

如果替换页脚,修改7、8行代码如下:
$Doc.PageSetup.footerDistance
$Word.ActiveWindow.ActivePane.View.SeekView = 10
发表于 2017-8-26 01:35:44 | 显示全部楼层
可以了 ,膜拜
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-5 16:14 , Processed in 0.072731 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表