Consulting

Results 1 to 9 of 9

Thread: Solved: Search and copy any instance of {bracketedtext}

  1. #1
    VBAX Regular
    Joined
    Jun 2010
    Posts
    18
    Location

    Solved: Search and copy any instance of {bracketedtext}

    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

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    You have to put a backslash in front of each curly bracket as they are special characters used in wildcard searches.

    [vba] .Text = "\{*\}"[/vba]

    David


  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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?

  4. #4
    VBAX Regular
    Joined
    Jun 2010
    Posts
    18
    Location
    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!

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    And how are you doing with this?

  6. #6
    VBAX Regular
    Joined
    Jun 2010
    Posts
    18
    Location
    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

  7. #7
    VBAX Regular
    Joined
    Jun 2010
    Posts
    18
    Location
    Wow! "\{*\}"! So simple...strange...this has frustrated me for a long time! Thanks again!

  8. #8
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    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

    David


  9. #9
    VBAX Regular
    Joined
    Jun 2010
    Posts
    18
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •