【发布时间】:2017-06-01 14:01:41
【问题描述】:
word VBA 程序员,
问题:在 MS word 中,用户会选择一个字符串(一个或多个单词),假设选择了“word1 word2”。如果有这样一个字符串后跟括号中的引用,即“word1 word2 (234, 21)”,宏将查看整个文档。从用户选择文本的点开始,将添加参考。 我有获取所选文本的代码: 暗淡 Sel 作为选择 暗淡特征作为字符串
Set Sel = Application.Selection
If Sel.Type <> wdSelectionIP Then
MsgBox Sel.text
End If
feature=sel.text
(特征是要查找的文本,后跟参考)
括号中文本的通配符是 (*),这意味着括号后面是任何更改,然后是右括号。
我的问题是以下代码不起作用:
With ActiveDocument.Content.Find
.ClearFormatting
.text = feature & \(*\)
With .Replacement
.ClearFormatting
.text = feature & \(*\)
.Font.Color = wdColorRed
End with
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = true
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
我什至无法运行它,因为这条线 .text = 特征 & (*)
变红了,不明白。
这里的问题是如何将变量的内容(用户选择的文本)与通配符结合起来,该通配符会给我该选定文本的实例,后跟括号,包括数字引用。
非常感谢。
【问题讨论】:
标签: vba ms-word wildcard substitution