View Single Post
 
Old 09-25-2023, 08:13 PM
Guessed's Avatar
Guessed Guessed is online now Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,993
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

At its simplest, it is just a simple find and replace that doesn't require special loop handling of the .Found result
Code:
Sub Macro1()
  Dim aRng As Range
  For Each aRng In ActiveDocument.StoryRanges
    With aRng.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = ""
      .Replacement.Text = ""
      .Font.Italic = True
      .Replacement.Style = ActiveDocument.Styles("Emphasis")
      .Forward = True
      .Wrap = wdFindContinue
      .Format = True
      .MatchCase = False
      .MatchWholeWord = False
      .MatchKashida = False
      .MatchDiacritics = False
      .MatchAlefHamza = False
      .MatchControl = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Execute Replace:=wdReplaceAll
    End With
  Next aRng
End Sub
However, there can be real complexity depending on what you are searching for. For instance, if there is content with a paragraph style including the Italic then the doubling up with a character style will remove the italics. This is because the Italics is a toggle setting and if italic is turned on twice (first by paragraph style and then by character style) then you have toggled it on, then off again.
Also, applying a character style to text which has multiple local font attributes (eg italic AND bold AND a different colour) will remove the 'other attributes' when the character style is applied.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote