Last active
November 28, 2022 11:35
-
-
Save jbasko/c5efaa928372dd1f161c073ff4ad8001 to your computer and use it in GitHub Desktop.
Clear character formatting in Word except for italics and superscript (macro)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub ResetFindParameters(oRng As Range) | |
With oRng.Find | |
.ClearFormatting | |
.Replacement.ClearFormatting | |
.Text = "" | |
.Replacement.Text = "" | |
.Forward = True | |
.Wrap = wdFindStop | |
.Format = False | |
.MatchCase = False | |
.MatchWholeWord = False | |
.MatchWildcards = False | |
.MatchSoundsLike = False | |
.MatchAllWordForms = False | |
.Execute | |
End With | |
End Sub | |
Sub FixParagraphs() | |
Debug.Print "<STARTED FIX PARAGRAPHS>----" | |
Dim range_Document As Range | |
Set range_Document = ActiveDocument.Range | |
Dim para As Paragraph | |
Dim range_found As Range | |
Dim obj_find As Find | |
For Each para In range_Document.Paragraphs | |
Dim italics_flag(1) As Boolean | |
italics_flag(0) = True | |
italics_flag(1) = False | |
For Each italics_enabled in italics_flag | |
Dim superscript_flag(1) As Boolean | |
superscript_flag(0) = True | |
superscript_flag(1) = False | |
Dim superscript_enabled As Variant | |
For Each superscript_enabled In superscript_flag | |
ResetFindParameters para.Range | |
Set obj_find = para.Range.Find | |
obj_find.Font.Italic = italics_enabled | |
obj_find.Font.Superscript = superscript_enabled | |
obj_find.Forward = True | |
obj_find.Execute | |
Do While obj_find.Found = True | |
Set range_found = obj_find.Parent | |
range_found.HighlightColorIndex = wdAuto | |
range_found.ParagraphFormat.Reset | |
range_found.Font.Reset | |
range_found.Font.Italic = italics_enabled | |
range_found.Font.Superscript = superscript_enabled | |
obj_find.Execute | |
Loop | |
Next | |
Next | |
Next | |
Debug.Print "----<ENDED FIX PARAGRAPHS>" | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment