word VBA programmers,
Problem: Working in MS word the user would select a string (one or several words), just asume "word1 word2" is selected. The macro would look in the whole document if there is such a string followed by references in parentheses i.e. "word1 word2 (234, 21)". From the point in which the user selected the text the references would be added. I have the code to get the selected text: Dim Sel As Selection Dim feature As String
Set Sel = Application.Selection
If Sel.Type <> wdSelectionIP Then
MsgBox Sel.text
End If
feature=sel.text
(feature being the text to look for followed by the references)
The wild card for the text into brackets would be (*) which means a parenthese followed by any change and followed by a close parenthese.
my problem is that the following code does not work:
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
I can not even run it because the line .text = feature & (*)
gets red and its not understood.
the problem here is how to combine the content of a variable (text selected by the user) with a wild card that would give me instances of that selected text followed by parentheses including numeral references.
Thanks a lot.