Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-05-2015, 12:10 PM
helal1990 helal1990 is offline Microsoft Word macro to find text, select all text between brackets, and delete Windows 7 64bit Microsoft Word macro to find text, select all text between brackets, and delete Office 2010 64bit
Novice
Microsoft Word macro to find text, select all text between brackets, and delete
 
Join Date: Feb 2015
Posts: 3
helal1990 is on a distinguished road
Default Microsoft Word macro to find text, select all text between brackets, and delete

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
Reply With Quote
 

Tags
macro



Similar Threads
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
Microsoft Word macro to find text, select all text between brackets, and delete VBA code for Microsoft Word macro — select text and insert footnote 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
Microsoft Word macro to find text, select all text between brackets, and delete How to find and select text in a document? mkhuebner Word VBA 8 02-04-2014 08:04 PM
Microsoft Word macro to find text, select all text between brackets, and delete Need help on Macro 03- Find text - if text is blank then remove line simpleonline1234 Word VBA 1 02-25-2011 02:28 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft