Results 1 to 10 of 10
  1. #1
    Star Lounger
    Join Date
    Jan 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replace {text:number} (Word 2000 SP3)

    I have a large document that I need to do a search and replace in and I'm not quite sure how to do it. I want to replace every instance of {text:number} with {text: number}. In other words, I want to find every instance of a colon that is enclosed by {} and add a space after it. I want the text and number to remain the same (they are different in each instance). Sometimes the number is a range, such as 245-6, rather than a single number.

    To clarify, I would like to change as follows:
    BEFORE: {Snellgrove, 1995 [1968] #374:13}
    AFTER: {Snellgrove, 1995 [1968] #374: 13}

    Ideally I'd like to use a macro to do this throughout the document (including footnotes) but I'm not sure how to do it. Many many thanks for any suggestions.

    regards,
    Abe

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Replace {text:number} (Word 2000 SP3)

    Select Edit | Replace...
    Click More.
    Tick the 'Use Wildcards' check box.
    In the 'Find what' box, enter <code>({*: )](*})</code>
    Note: remove the space between : and )
    In the 'Replace with' box, enter <code>1 2</code>
    Click 'Replace All'.

    Macro code to do this is
    <code>
    With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    ' In the next line, remove the space between : and )
    .Text = "({*: )(*})"
    .Replacement.Text = "1 2"
    .Forward = True
    .Wrap = wdFindAsk
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
    End With
    </code>
    Look up Find and Replace in the online help for an explanation of the symbols used in the 'Find what' and 'Replace with' boxes.

  3. #3
    Star Lounger
    Join Date
    Jan 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace {text:number} (Word 2000 SP3)

    Hi Hans,

    Many thanks for the response. Unfortunately it didn't work, either by running Find/Replace, or by using a Macro.

    When I try running Find/Replace, I get "The Find What text contains a Pattern Match expression which is not valid" The Find What text I used was, from your suggestion:
    ({*(smile)(*})

    When I try to run it as a macro I get "Compile Error: Invalid Outside Procedure."

    Any idea what could be causing these errors?

    Many thanks for any help.

    regards,
    Abe

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Replace {text:number} (Word 2000 SP3)

    Both the Lounge software and AutoCorrect in Word play havoc with : followed by ) without a space in between: it becomes a smiley / smile character. VBA shouldn't do this, however. But you must put the code inside a Sub ... End Sub pair. See attached document.
    Attached Files Attached Files

  5. #5
    Star Lounger
    Join Date
    Jan 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace {text:number} (Word 2000 SP3)

    Many thanks Hans. Unfortunately, I'm a bit confused about macros in general. I tried to run the macro in the attached document but I got an error telling me that the macros in this project are disabled. I also tried to copy the macro into another document, but I couldn't make that work either. Ideally, I'd like to have it accessible from all of my files, which I think means that I want to put it in normal.dot but I can't seem to do that in a way that works. Many thanks for any suggestions.
    regards,
    Abe

  6. #6
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace {text:number} (Word 2000 SP3)

    Hi Abe:
    If you:
    1. Tick "Use wildcards" in the Find/Replace dialog box,
    2. Copy the Find what expression that Hans' posted above, &
    3. Remove the space after the colon, it should work.
    Cheers,

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Replace {text:number} (Word 2000 SP3)

    Do you have macro security set to High (in Tools | Macro | Security...)? That would disable all macros. If so, set macro security to Medium. Word will prompt you if you want to enable macros if you open a document with macros.

    You should be able to copy the macro to a module in Normal.dot. If you tick "Trust all installed add-ins and templates" in the Trusted Sources tab of the Security dialog, you should be able to run macros in Normal.dot without problems.

  8. #8
    Star Lounger
    Join Date
    Jan 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace {text:number} (Word 2000 SP3)

    Yes, changing the Macro setting enabled me to run the macro. Thanks!

    Unfortunately, the macro didn't work quite right. Sometimes it inserted a space between the colon and the numeral when there already was one; sometimes it didn't insert at all. I'm not sure why, but it might be related to the fact that there are *lots* of these curly brackets throughout the document (I use them for endnote citations). Also it didn't have any effect on text in footnotes.

    However, now that I look more closely, I realize that the find/replace is much simpler than I had thought (sorry! I should have spotted this before.). In fact, I think all I need is a search and replace that will find:
    number:number
    and change it to:
    number: number
    where the numbers remain the same both before and after the search.

    If I did this with a Find/Replace, I think the Find What box would be:
    ^#:^#
    But what would the Replace box be?

    Many thanks for all the help. I appreciate it deeply!

    Abe

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace {text:number} (Word 2000 SP3)

    If you want to replace:
    number:number with
    number: number

    you must use wildcards.
    Find: ([0-9]{1,})[img]/forums/images/smilies/sad.gif[/img][0-9]{1,})
    Replace: 1 2
    Note there is a space after the "1".

  10. #10
    Star Lounger
    Join Date
    Jan 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace {text:number} (Word 2000 SP3)

    Excellent! Many thanks for the help. Once I finish this project I really need to learn all that syntax myself.
    best,
    Abe

Posting Permissions

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