![]() |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
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# Last edited by macropod; 02-05-2015 at 02:14 PM. Reason: Deleted multiple links to stackoverflow.com |
Tags |
macro |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to find text in between two characters and then format selected text? | qcom | Word | 5 | 02-19-2015 11:23 PM |
![]() |
ndnd | Word VBA | 10 | 01-06-2015 01:47 PM |
Macro to find coloured text and replace with form-field/formtext containing that text | tarktran | Word VBA | 1 | 11-26-2014 08:12 AM |
![]() |
mkhuebner | Word VBA | 8 | 02-04-2014 08:04 PM |
![]() |
simpleonline1234 | Word VBA | 1 | 02-25-2011 02:28 AM |