View Single Post
 
Old 11-21-2018, 04:27 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
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