Log in

View Full Version : Solved: Search and copy any instance of {bracketedtext}



AaronT
06-24-2010, 02:27 PM
Hello,

I am attempting to loop through an word doc and copy any instance of bracketed text like "{thiswouldbecopied}". I am having difficulty with the brackets as chr(123) & "*" & chr(125) as my search string with searchwildcards=true is returning an error.

I know that the built in search and replace will not allow for searches of {} so I thought I could do it with VBA.

Any assistance would be much appreciated. Thank you!

Aaron

Tinbendr
06-24-2010, 06:13 PM
You have to put a backslash in front of each curly bracket as they are special characters (http://word.mvps.org/faqs/general/UsingWildcards.htm) used in wildcard searches.

.Text = "\{*\}"

fumei
06-25-2010, 07:58 AM
I know that the built in search and replace will not allow for searches of {} As Tinbendr points out, this is not correct. Search and Replace can look for {}.

However, you mention "copy". This is not the same and Find/Replace. If you are doing a Find/Replace you do NOT need VBA. If you are doing a copy of some sort, you may have to.

What exactly are you doing?

AaronT
06-25-2010, 08:03 AM
Thank you Gerry and Tinbendr for your quick responses! This helped a lot!

My goal is to create a sub that will loop through my word doc, find any instance of text within these brackets, copy the string to the clipboard and then paste it into an excel spreadsheet. I'm essentially trying to create a log of bracketed text.

I hope this makes sense.

Again, thank you for the quick help!

fumei
06-25-2010, 08:04 AM
And how are you doing with this?

AaronT
06-25-2010, 08:07 AM
Just started working on it. :-) I think I have the looping down and gettting a msgbox with text for each instance, which is good. The next challenge will be to interface with excel to paste the text into a spreadsheet.

Aaron

AaronT
06-25-2010, 08:14 AM
Wow! "\{*\}"! So simple...strange...this has frustrated me for a long time! Thanks again!

Tinbendr
06-25-2010, 03:53 PM
copy the string to the clipboard and then paste it into an excel spreadsheet.No need for these extra steps. Insert it directly into Excel from Word.

When you get ready, post a new question along with sample xls/doc (in a zip) and we'll show you how.

David

AaronT
06-25-2010, 08:25 PM
Wow! Thank you, David! I'll do that now. I'm really impressed that you guys have been so responsive and helpful. This is a great resource for "wannabe" VBA pros. :-) Thanks again!

Aaron