|
-
Mar 10th, 2004, 11:42 AM
#1
Thread Starter
New Member
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
-
Mar 11th, 2004, 04:29 AM
#2
Addicted Member
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
-------------------------------
-
Mar 11th, 2004, 05:50 AM
#3
Thread Starter
New Member
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
-
Mar 11th, 2004, 06:23 AM
#4
Addicted Member
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
-
Mar 15th, 2004, 03:09 AM
#5
Addicted Member
<<wouldnt you need a FindNext >>
No because of :-
Replace:=wdReplaceAll
I have tested this code and it works OK in Excel 97.
Regards
BrianB
-------------------------------
-
Mar 15th, 2004, 03:10 AM
#6
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|