Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Replace Styles Macro - Endless Loop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CASabre - 06 Sep 2006 16:08 GMT
Hi Everyone,

A couple of years ago, with much help from this group, I got a cool
macro that would go through a document and replace specific styles with
a different specific style. It worked great in Word 2000.

We have recently moved to Word 2003, and when I run the macro, it gets
stuck in an infinite loop if one of the styles specified in the "Find
Style" array does not exist in that particular document.

I'm sure it's a simple fix, but I'm not sure what I need to change.
It's been a couple of years since I've done any macro work, so I've
pretty much forgotten everything I learned.

Any help would be greatly appreciated!

---

Dim FindStyle As Variant, ReplaceStyle As Variant, k As Integer
FindStyle = Array("Style1", "Style2", "Style3", "Style4", "Style5")
ReplaceStyle = Array("Heading 2", "Heading 3", "Heading 4", "Heading
5", "Body Text1")
On Error Resume Next
With ActiveDocument.Range.Find
  For k = LBound(FindStyle) To UBound(FindStyle)
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = ""
      .Replacement.Text = ""
      .Format = True
      .Style = FindStyle(k)
      .Replacement.Style = ReplaceStyle(k)
          Do While .Execute(Replace:=wdReplaceAll)
          Loop
  Next
End With
End Sub
Russ - 06 Sep 2006 17:49 GMT
You could test for the .inuse property. See VBA Help.

> Hi Everyone,
>
[quoted text clipped - 33 lines]
> End With
> End Sub

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

CASabre - 06 Sep 2006 20:59 GMT
Hmmm, I could, couldn't I?

See, I *knew* there was a simple solution. Thanks Russ!

> You could test for the .inuse property. See VBA Help.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.