ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 8963|回复: 7

[求助] 请问word如何才能查找多个关键词?

[复制链接]

TA的精华主题

TA的得分主题

发表于 2015-6-16 10:06 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
如题。比如一篇英文段落,The villagers of Little Hangleton still called it “the Riddle House,” even though it had been many years since the Riddle family had lived there. It stood on a hill overlooking the village, some of its windows boarded, tiles missing from its roof, and ivy spreading unchecked over its face. Once a fine-looking manor, and easily the largest and grandest building for miles around, the Riddle House was now damp, derelict, and unoccupied.The Little Hangletons all agreed that the old house was “creepy.” Half a century ago, something strange and horrible had happened there, something that the older inhabitants of the village still liked to discuss when topics for gossip were scarce. The story had been picked over so many times, and had been embroidered in so many places, that nobody was quite sure what the truth was anymore. Every version of the tale, however, started in the same place: Fifty years before, at daybreak on a fine summer’s morning, when the Riddle House had still been well kept and impressive, a maid had entered the drawing room to find all three Riddles dead.

我要从中同时查找选中“unchecked”“creepy”“ maid”这三个关键词并加粗,使之形成一下效果:
The villagers of Little Hangleton still called it “the Riddle House,” even though it had been many years since the Riddle family had lived there. It stood on a hill overlooking the village, some of its windows boarded, tiles missing from its roof, and ivy spreading unchecked over its face. Once a fine-looking manor, and easily the largest and grandest building for miles around, the Riddle House was now damp, derelict, and unoccupied.The Little Hangletons all agreed that the old house was “creepy.” Half a century ago, something strange and horrible had happened there, something that the older inhabitants of the village still liked to discuss when topics for gossip were scarce. The story had been picked over so many times, and had been embroidered in so many places, that nobody was quite sure what the truth was anymore. Every version of the tale, however, started in the same place: Fifty years before, at daybreak on a fine summer’s morning, when the Riddle House had still been well kept and impressive, a maid had entered the drawing room to find all three Riddles dead.


————————————————————————————————————————————————————————————————

请教以上操作word可以实现吗?或者如何用vba实现呢?代码应该怎么写呢?

本人是菜鸟中的菜鸟,对VBA一窍不通,因为有此需求特地注册此号前来求助,还请大神讲解的详细一些,谢谢!!!!!

TA的精华主题

TA的得分主题

 楼主| 发表于 2015-6-16 20:38 | 显示全部楼层
因为文章很长,关键词很多,所以想寻求一个更有效率的方法

TA的精华主题

TA的得分主题

发表于 2015-6-21 18:44 | 显示全部楼层
zzyuzi 发表于 2015-6-16 20:38
因为文章很长,关键词很多,所以想寻求一个更有效率的方法

我简单做了一个

  1. Sub findKeyWrod(mykeyword As String)
  2. '
  3. '    宏1 宏
  4. '
  5. '
  6.     Selection.Find.ClearFormatting
  7.     Selection.Find.Replacement.ClearFormatting
  8.     With Selection.Find.Replacement.Font
  9.       
  10.         .Bold = True
  11.     End With
  12.     With Selection.Find
  13.         .Text = mykeyword
  14.         .Replacement.Text = ""
  15.         .Forward = True
  16.         .Wrap = wdFindAsk
  17.         .Format = True
  18. '        .MatchCase = False
  19. '        .MatchWholeWord = False
  20. '        .MatchByte = False
  21. '        .MatchWildcards = False
  22. '        .MatchSoundsLike = False
  23. '        .MatchAllWordForms = False
  24.     End With
  25.     Selection.Find.Execute Replace:=wdReplaceAll
  26. End Sub


  27. Sub tttt()
  28.    
  29.     Dim arr
  30.    
  31.     Dim i As Integer
  32.    
  33.    
  34.     arr = Array("unchecked", "creepy", "maid")
  35.    
  36.     For i = 0 To UBound(arr)
  37.         Call findKeyWrod(CStr(arr(i)))
  38.     Next
  39. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2015-6-22 09:29 | 显示全部楼层
3楼的朋友,在运行代码之后,显示如图所示的错误:
无标题.png

TA的精华主题

TA的得分主题

 楼主| 发表于 2015-6-25 22:20 | 显示全部楼层

我搜到了一篇代码解决了,不过也非常感谢你的回复!谢谢

TA的精华主题

TA的得分主题

发表于 2016-3-21 21:39 | 显示全部楼层
楼主,你好,我也正在找这方面的解决方法,你的代码能给分享一下么,邮箱remon112@163.com,感谢!!

TA的精华主题

TA的得分主题

发表于 2022-1-19 17:12 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2022-7-25 15:01 | 显示全部楼层
bsyjfen 发表于 2022-1-19 17:12
这个代码能用,就是要点几次确定。

加上Application.DisplayAlerts = False 就不用多点了
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-23 03:00 , Processed in 0.044576 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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