找回密码
 加入
搜索
查看: 10154|回复: 11

[AU3基础] 【已解决】AU3操作word VBA对象,实现遍历文档内容找出关键字

[复制链接]
发表于 2014-4-24 14:01:05 | 显示全部楼层 |阅读模式
本帖最后由 mpf5566 于 2014-4-25 15:49 编辑
Global $word = ObjCreate("word.application")
$word.visible = True
dim $kword1[100]=[*****]
$wb=$word.documents.open("路径\XX.docx")
For $i = 0 To UBound($kword1) - 2
        $wb.application.selection.find($kword1[$i], "",true, 1,False, False, False,True, False, False,False).font.color = 128
以查找的方式搜索word符合数组关键字并使字体显示为深红色为什么无法实现,求助!
发表于 2014-4-24 19:31:39 | 显示全部楼层
本帖最后由 kevinch 于 2014-4-24 19:33 编辑
With $wb.application.selection.find
        .clearformating
        .replacement.clearformating
        .replacement.font.colorindex=6
        For $n=0 To UBound($kword1)-1
                .Execute($kword1[$n], Default, Default, Default, Default, Default, Default, Default, Default, $kword1[$n], 2)
        Next
EndWith
这个试下
 楼主| 发表于 2014-4-25 11:06:06 | 显示全部楼层
回复 2# kevinch
果然可以了,多谢kevinch老师,之前excel帮助很大,这次word又靠你了,VBA高手赞个!!
 楼主| 发表于 2014-5-19 14:39:06 | 显示全部楼层
回复 2# kevinch

再请教下kevinch老师,我想在execute找到关键字的基础上追加上加粗关键字,查询语句后VB给的是
表达式.bold= true 可以实现加粗,然后我在
For $n = 0 To UBound($kword1) - 1
                                                        .Execute($kword1[$n], Default, Default, Default, Default, Default, Default, Default, Default)
                                                        .selection.font.bold = True
                                                       
                                                Next

   加了 .selection.font.bold = True 但是跑起来不起作用。。。请指点
发表于 2014-5-19 16:30:33 | 显示全部楼层
With $wb.application.selection.find
        .clearformating
        .replacement.clearformating
        .replacement.font.colorindex=6
        .replacement.font.bold = true
        For $n=0 To UBound($kword1)-1
                .Execute($kword1[$n], Default, Default, Default, Default, Default, Default, Default, Default, $kword1[$n], 2)
        Next
EndWith
没测试,你先这样试下
 楼主| 发表于 2014-5-19 18:13:40 | 显示全部楼层
回复 5# kevinch


    多谢您的答复,这个之前已经编译过,还是无法达到加粗的效果。^ ^
发表于 2014-5-19 20:02:57 | 显示全部楼层
回复 6# mpf5566
With $wb.application.selection.find
        .clearformating
        .replacement.clearformating
        .replacement.font.colorindex=6
        .replacement.font.bold = true
        For $n=0 To UBound($kword1)-1
                .Execute($kword1[$n], Default, Default, Default, Default, Default, Default, Default, True, $kword1[$n], 2)  ;这里要改一个参数(本例的倒数第三个),表示替换格式
        Next
EndWith
发表于 2014-5-19 20:19:25 | 显示全部楼层
I'm studying.
发表于 2014-6-10 23:06:04 | 显示全部楼层
请教kevinch 前辈,如何上标WORD内的字符啊?不是使用Ctrl+Shift++(加号)快捷的方法。谢谢先!
发表于 2014-6-11 21:03:39 | 显示全部楼层
回复 9# gb23
用前面的替换代码,设置替换格式为上标
.replacement.font.superscript=true
这样试下
发表于 2014-6-12 00:19:50 | 显示全部楼层
Global $word = ObjCreate("word.application")
$word.visible = True
dim $kword1="你"
$wb=$word.documents.open("C:\Documents and Settings\Administrator\桌面\1.docx")
With $wb.application.selection.find

        .clearformating

        .replacement.clearformating

        .replacement.font.colorindex=6

        .replacement.font.bold = true

        .Execute($kword1, Default, Default, Default, Default, Default, Default, Default, Default, $kword1, 2)

EndWith
kevinch  前辈 还有楼主~~其实我连这个楼主搞定的选字变色都还没有搞定~~

C:\Documents and Settings\Administrator\??\sdsdf.au3 (8) : ==> The requested action with this object has failed.:

为什么对象请求失败呢?
发表于 2017-3-30 21:27:30 | 显示全部楼层
vba有自动录制的,我发现wordvba代码 只要家了对象就能直接运行了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-3-29 22:57 , Processed in 0.087283 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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