ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
12
返回列表 发新帖
楼主: 重远

[求助] word中数字的查找比较与替换

[复制链接]

TA的精华主题

TA的得分主题

发表于 2021-10-28 08:55 | 显示全部楼层
重远 发表于 2021-10-26 12:31
yxingsong老师的代码我也试了下,有个地方报带指定名称的项目不存在,不知道怎么回事

第一次替换其实就是将这种格式72.,73.的这种类型格式前加=,理论上来说,可以一起加\=,但是\号是转义字符,需用两个\\表示一个\,但是执行时会不成功,所以分成了两部分,用通配符可以轻松解决很多问题,我给你的时直接录制的代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2021-10-28 11:46 | 显示全部楼层
以前看过一些关于VBA的教程,感觉太难就放弃了。这中间用文本编辑软件的正则替换过一些东西,感觉还是用软件干活比人工快很多。但是文本编辑软件替换东西也是有限制的。象这种情况在那里面是没办法处理,这时就又想到了直接在word里面处理多好。看了老师们的贴子,收获很多。只是现在还是个代码小白,只能一点一点的学。有时感觉会写个替换的代码了吧,一下手又不对。

TA的精华主题

TA的得分主题

发表于 2021-10-29 00:23 | 显示全部楼层
  1. Sub FindActiveDocument()
  2. '全文查找/光标不动/不激活对象/速度极快!
  3.     With ActiveDocument.Content.Find
  4.         .ClearFormatting
  5.         .Text = "[0-9.,,  ^s^t]{1,}元"
  6.         .Forward = True
  7.         .MatchWildcards = True
  8.         Do While .Execute
  9.             With .Parent
  10.                 .Font.ColorIndex = wdRed
  11. '                .Start = .End
  12.             End With
  13.         Loop
  14.     End With
  15. End Sub
  16. Sub FindRange()
  17. '区域查找/未选则全选/光标不动/不激活对象/速度极快!
  18.     Dim r As Range
  19.     Set r = IIf(Selection.Type = wdSelectionIP, ActiveDocument.Content, Selection.Range)
  20.     With r.Find
  21.         .ClearFormatting
  22.         .Text = "[0-9.,,  ^s^t]{1,}元"
  23.         .Forward = True
  24.         .MatchWildcards = True
  25.         Do While .Execute
  26.             With .Parent
  27.                 If Not Selection.Type = wdSelectionIP Then
  28.                     If .End > Selection.End Then Exit Do
  29.                 End If
  30.                 .Font.ColorIndex = wdRed
  31. '                .Start = .End
  32.             End With
  33.         Loop
  34.     End With
  35. End Sub
  36. Sub FindSelection()
  37. '从插入点向后查找/光标移动/激活对象/速度较慢/尽量少用!
  38.     With Selection
  39. '        .HomeKey 6
  40.         With .Find
  41.             .ClearFormatting
  42.             .Text = "[0-9.,,  ^s^t]{1,}元"
  43.             .Replacement.Text = ""
  44.             .Forward = True
  45.             .MatchWildcards = True
  46.             Do While .Execute
  47.                 With .Parent
  48.                     .Font.Color = wdColorRed
  49. '                    .Start = .End
  50.                 End With
  51.             Loop
  52.         End With
  53.     End With
  54. End Sub
  55. Sub FindBold()
  56. '取消加粗
  57.     With ActiveDocument.Content.Find
  58.         .ClearFormatting
  59.         .Font.Bold = True
  60.         With .Replacement
  61.             .ClearFormatting
  62.             .Font.Bold = False
  63.         End With
  64.         .Execute Findtext:="", ReplaceWith:="", Format:=True, Replace:=wdReplaceAll
  65.     End With
  66. End Sub
  67. Sub FindReplace()
  68.     ActiveDocument.Content.Find.Execute Findtext:="a", MatchWildcards:=True, ReplaceWith:="b", Replace:=wdReplaceAll
  69.     ActiveDocument.Content.Find.Execute "[一-﨩]@", , , 1, , , , , , "", 2
  70. End Sub
复制代码

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

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

GMT+8, 2024-5-5 16:51 , Processed in 0.034950 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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