View Single Post
 
Old 01-20-2021, 09:07 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Paul, here both of those returned the same result the OP is seeing.


Ruud, back to your original observation, it does seem that the length of the italic string in the paragraph text is having and affect. I copied your line 2 as lines 4 and 5. Then shortened the italic string in line 4. Ran your macro and lines 2 and 5 were not converted to all normal font.

I don't know why that is happening. I don't know how helpful this will be for your production documents, but for this example, this worked:

Code:
Public Sub flatten()
Dim oRng As Range
Dim wPara As Word.Paragraph
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Font.Italic = True
    .Replacement.Text = "<i>^&</i>"
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
  For Each wPara In Word.ActiveDocument.Paragraphs
    wPara.Style = ActiveDocument.styles(wdStyleNormal).NameLocal
  Next
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .ClearFormatting
    .Text = "(\<i\>)(*)(\</i\>)"
    .MatchWildcards = True
    .Replacement.Text = "\2"
    .Replacement.Font.Italic = True
    .Execute Replace:=wdReplaceAll
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote