Results 1 to 13 of 13
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Search and replace in Word (Word xp)

    I need to search for the word Page: 1, Page: 2, through Page: 1600 in a word document and make both the words bold. The entire file is in courier type face but i want the page numbers to be in courier bold face. I can make the word Page: bold but don't know how to get the sequential numbers to be bold. How can i do this in a macro, vba code? thank you for the help.

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

    Re: Search and replace in Word (Word xp)

    Is this page number a field in the header or footer of the document?
    If so, does your document have multiple sections with non-linked headers/footers?
    If not, are the page numbers cross reference fields?

  3. #3
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Search and replace in Word (Word xp)

    no, the page numbers are just text, not a head, footer or cross reference. This is a large ASCII file i put into word so i could write a macro to search for the page numbers and make them bold. thank you for the help.

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

    Re: Search and replace in Word (Word xp)

    You don't really need VBA for this:

    Select Edit | Replace...
    Click the More button.
    Tick the Wildcards check box.
    Enter this expression in the Find what box: Page: [0-9]{1;4}
    This means: the text "Page: " followed by one to four digits.
    Enter this expression in the Replace with box: ^&
    This means: the text in the Find what box.
    With the insertion point still in the Replace with box, click Format, and select Font...
    Click on Bold, then OK.
    Click Replace All.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Search and replace in Word (Word xp)

    Just a footnote: the graphic shows the Find What box as having a Bold format, but one should follow the instructions and not the graphic on that point.

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

    Re: Search and replace in Word (Word xp)

    Oops, yes, I overlooked that. Thanks for pointing it out.

  7. #7
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Search and replace in Word (Word xp)

    ok, thank you very much. It turns out i have to search for the word "Table" with a sequential number after it and then format the line below it to bold.

    i'm trying something like this...

    Sub Macro5()
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "Table [0-9]{1,4}"

    Selection.MoveDown Unit:=wdLine, Count:=1
    'code to bold this line
    'code to find the next instance of Table ####
    'bold one line below it


    Can u tell me what the code is for this sub? thank you very much.

  8. #8
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Search and replace in Word (Word xp)

    A "line" is not a distinct object in Word. Assuming that the next line is a whole paragraph, you want
    <font face="Georgia">selection.Paragraphs(1).Range.Font. Bold = True</font face=georgia>


    StuartR

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

    Re: Search and replace in Word (Word xp)

    Try this:

    Sub Macro5()
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .MatchWildcards = True
    .Text = "Table [0-9]{1;4}"
    Do While .Execute
    Selection.Move Unit:=wdParagraph
    Selection.MoveDown Extend:=wdExtend
    Selection.Font.Bold = True
    Selection.Collapse Direction:=wdCollapseEnd
    Loop
    End With
    End Sub

  10. #10
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Search and replace in Word (Word xp)

    okay, so i tried this

    Sub Macro5()
    Selection.WholeStory

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    For i = 1 To 5
    With Selection.Find
    .Text = "Table " & i
    Selection.MoveDown Unit:=wdLine, Count:=1
    Selection.Paragraphs(1).Range.Font.Bold = True
    End With
    Next i


    End Sub

    =================

    Do i have to select the whole story to do a find and replace. I'm used to excel rather than word. How do i iterate through the "rows/lines" in word to find the instances of "Table ###" without selecting the whole story? thank you

  11. #11
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Search and replace in Word (Word xp)

    <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35>

    it works!!!

  12. #12
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Search and replace in Word (Word xp)

    i just realized that i'm trying to do this from Excel.

    i have

    Set oWdDoc = oWdApp.Documents.Open(WordFileName)
    oWdDoc.Activate
    but don't know how to selection the whole document.

    i tried oWdDoc.selection or oWdDoc.wholestory but that doesn't work. Please advise. thanks much

  13. #13
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Search and replace in Word (Word xp)

    Try oWdApp.Selection.WholeStory

    StuartR

Posting Permissions

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