【发布时间】:2011-09-10 20:57:51
【问题描述】:
请帮忙!!!
我有一个正在尝试修复的 Microsoft Word 的 VBA 宏。 宏的目的是匹配双花括号 {{anything}} 内的任何内容,但是大括号必须在同一行中打开和关闭。 完成匹配后,我需要能够应用更改格式、样式、颜色等,并应用一些其他更改选定的文本。
我需要搜索的 .doc 有表格、绘制文本框和其他对象,这就是为什么我想使用 ms word 中的普通搜索。
例子:
{{1,000.00}} match (1)
{{Interesting}} match (1)
{{Within}} match (1)
{{1’100.00’}} match (1)
**{{01A10}} {{01A10}}** match (2) twice
{{ 1 }} match (1)
{{10-}} {{-10}} match (2) twice
[[1252}} No match (0)
{{8888888.99 No match (0), because close curly braces are in a new line
}}
{{}} match (1)
{{1’000’000.05}} match (1)
{{ No match (0)
}} No match (0)
我已经尝试过这个“[{]{2}[}]{2}”,但它不起作用,它会带来不想要的结果。 任何帮助将不胜感激。
雇用是我的代码:
Sub GetTotalReport()
Dim totalReport As Double
Dim placeHolderRep As Variant
Dim placeHolder As Variant
ActiveDocument.Select
totalReport = 0#
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[\{]{2}<*>[\}]{2}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
Do While .Execute
With Selection
.Font.Italic = True
.Font.Bold = True
If Not .Text = "" Then
placeHolderRep = Mid(.Text, 3, Len(.Text) - 4)
.Text = placeHolderRep
placeHolder = placeHolderRep
placeHolder = Replace(Replace(Replace(placeHolder, ",", ""), "'", ""), "’", "")
totalReport = totalReport + Val(placeHolder)
End If
End With
Loop
End With
End Sub
【问题讨论】:
标签: vba search ms-word wildcard