Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    May 2002
    Location
    Smithfield, Free State, South Africa
    Posts
    210
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replace styles (MS Word 2000/2003)

    How do I create a macro to find and replace all occurances or a style with another style?
    I recorded one and it works fine while recording, but if I run it later, it does not work.
    Here is my code:
    StyleReplace02 Macro

    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("NumResN")
    Selection.Find.ParagraphFormat.Borders.Shadow = False
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Style = ActiveDocument.Styles("NumResNF")
    Selection.Find.Replacement.ParagraphFormat.Borders .Shadow = False
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub

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

    Re: Replace styles (MS Word 2000/2003)

    If you only want to replace one style with another, remove the lines

    Selection.Find.ParagraphFormat.Borders.Shadow = False

    and

    Selection.Find.Replacement.ParagraphFormat.Borders .Shadow = False

    They impose extra restrictions on the find/replace process.

  3. #3
    3 Star Lounger
    Join Date
    May 2002
    Location
    Smithfield, Free State, South Africa
    Posts
    210
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace styles (MS Word 2000/2003)

    Thanks Hans ... and of course it worked!!

    Cheers

Posting Permissions

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