Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 11-21-2018, 04:27 PM
Guessed's Avatar
Guessed Guessed is offline Infinite Loop when Finding Styles Windows 10 Infinite Loop when Finding Styles Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I would approach this task from a different direction.

Firstly, if you have control of the receiving file PRIOR to introducing the other content, add a couple of aliases to the heading styles so that the conversion of Epic Title and Main Topic to headings happens automatically as you paste.

Add an alias to Heading 3 by modifying the style for Heading 3 so its name is "Heading 3,Epic Title". Do the same for Heading 1 so its name becomes "Heading 1,Main Topic".

Note: You can't add an alias if that style name already exists in the document so it has to happen BEFORE pasting in the content from the other source. But once it is done, anything that was styled with either Heading 3 OR Epic Title will paste into the document as Heading 3.

So then, all that remains is the question you posted about. I would rewrite that part of the macro along the following lines.
Code:
Sub ChangeActiveDocument()
  Dim aRng As Range, iHeadStyleID As Integer
  For iHeadStyleID = -4 To -2    '-4=wdStyleHeading3, -2=wdStyleHeading1
    Set aRng = ActiveDocument.Range
    With aRng.Find
      .ClearFormatting
      .Style = iHeadStyleID
      .Wrap = wdFindStop
      .Forward = True
      .Text = ""
      Do While .Execute
        aRng.ParagraphFormat.Reset
        aRng.Font.Reset
      Loop
    End With
  Next
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Infinite Loop when Finding Styles Infinite loops occurring in find and replace functions in word macro Thefirstfish` Word VBA 5 04-06-2017 07:18 PM
MACRO in infinite loop when it encounters user defined figure label photoval Word VBA 3 02-02-2016 08:26 PM
Outlook 2013 - caught in an infinite loop on startup borderfox Outlook 0 07-26-2015 01:40 PM
Infinite Loop when Finding Styles Finding and replacing fonts and styles Adriano Word VBA 10 03-17-2013 07:08 PM
'Infinite Loop' error with Infopath 2010 Debbie25 Misc 2 05-18-2011 08:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft