Hello,
I'm trying to write a word macro that will find text that will be enclosed between brackets, and select everything between the brackets, then delete.
The text will need to be input from the user as a full model number like this:
MVAV-A1-B3-C2 ...etc, where A1, B3, and C2 are different configurations.
The word file is written like this (for example): The unit will use [A1 - chilled water] [A2 - compressors] for cooling.
Based on a model # MVAV-A1, I want the macro to search for all text "A2" (the negative of A1) in the word doc, select/highlight everything between the brackets "[A1 - compressors]", and delete it.
So far I'm just trying to get it to find a single instance of "A1", and then find the nearest [ bracket to the left, and ] bracket to the right, and select everything in between. Then eventually put it in a loop.
With the research that I've done, I've got this, which obviously does not do the job:
Sub EditFindLoopExample()
With Selection.find .ClearFormatting .Text = "1A" .Forward = True .MatchWildcards = False .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Extend Selection.find.ClearFormatting With Selection.find .Text = "]" .Replacement.Text = "" .Forward = True .Wrap = wdFindAsk .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With With Selection.find
.Text = "]"
.Forward = True
.Execute
.Text = ""
End With End Sub
I was wondering if anyone here can help me fill the blanks on how to get this to work. Any help would be greatly appreciated.
Thanks for reading.
Admin Note: Deleted multiple embedded links to post at
http://stackoverflow.com/questions/28351992/microsoft-word-macro-to-find-text-select-all-text-between-brackets-and-delete#