Results 1 to 6 of 6

Thread: Find/Replace Loop - argh !

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    2

    Find/Replace Loop - argh !

    Hi there,

    I am trying to run a simple macro (which I did by recording it) that looks for style "TableAnchor", replaces the line of it with another style, and puts another paragraph in after it in a third style.
    No problems. But I want to do it for every instance of "TableAnchor" style. And I am stumped as to where and what sort of loop to use.
    Any hints would be reaaaaaaaaallllllllly appreciated.
    Here's my macro so far:
    Sub replacingstyles()
    '
    ' replacingstyles Macro
    ' Macro recorded 10/03/04 by elizabeth.dent
    '
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("TableAnchor")
    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
    Selection.Style = ActiveDocument.Styles("Body Text")
    Selection.EndKey Unit:=wdLine
    Selection.TypeParagraph
    Selection.Style = ActiveDocument.Styles("TableAnchor1point")
    End Sub
    Thanks a lot,
    Emmeline

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    Try this :-

    Code:
        With Selection.find
            .ClearFormatting
            .Style = ("TableAnchor")
            .Replacement.ClearFormatting
            .Replacement.Style = ("TableAnchor1point")
            .Execute FindText:="", ReplaceWith:="", _
                Replace:=wdReplaceAll, Format:=True
        End With
    Regards
    BrianB
    -------------------------------

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    2
    Nope that still only does the one instance.
    Plus I don't want just to do a find/replace.
    I want to do a find with one style, and while that instance is selected, put a paragraph in another style after it, then find the next instance...

    Sorry. I'm so stumped and i bet it's really easy.

    Emmeline
    x

  4. #4
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202
    wouldnt you need a FindNext somewhere in there?

    i would think it would only find the first instance, then replace and stop.

    using FindNext would continue?

    just a thought..

    Brian
    if you fail to plan, you plan to fail

  5. #5
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    <<wouldnt you need a FindNext >>
    No because of :-
    Replace:=wdReplaceAll

    I have tested this code and it works OK in Excel 97.
    Regards
    BrianB
    -------------------------------

  6. #6
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    er .. that should be Word 97.
    Regards
    BrianB
    -------------------------------

Posting Permissions

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



Click Here to Expand Forum to Full Width