Storing Values From within find
Hi,
I was just wondering if there is a way to store a valur that turns up within
Selection.Find.Text
Consider the following code
VB Code:
Sub style_tag()
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("H1")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "^&"
.Replacement.Font.Color = wdColorBlue
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.EscapeKey
End Sub
Now the above code finds where the style name H1 has been applied and highlights the selected text to blue.
Is there a way in which i can store the resultant text in a variable?
Example: if the style h1 is applied to a word "Chapter 1" then this code searches h1 style and highlights "Chapter 1" to blue. Is there a way in which i can store the highlighted text in a variable?
Re: Storing Values From within find
This is jsut an educated guess, but shouldnt be far wrong:
VB Code:
MyVariable = Selection.Text
Re: Storing Values From within find
Quote:
MyVariable = Selection.Text
This just stores the text in which the cursor is positioned
Re: Storing Values From within find
Where in your code did you place it? I think it would work if placed just before/after "Selection.EscapeKey". (if not, you may need to find & store before replacing).
Note that it will only find the last value changed, as you are replacing all instances in one go - to get all of them you would need to replace just one at a time.