In the past I have been frustrated by the absence of "clean direct formatting" only in MS Word. I must admit it may exist hidden in some menu I can't find, but since I found the methods for that purpose in VBA I decided to create three small macro that will simply remove either direct paragraph formatting, character formatting or both to the selected text.
Sub Clean_Direct()
'
' Delete direct formatting to paragraph and character
'
'
Selection.ClearCharacterDirectFormatting
Selection.ClearParagraphDirectFormatting
End Sub
Sub Clean_Direct_character()
'
' Delete direct formatting to character
'
'
Selection.ClearCharacterDirectFormatting
End Sub
Sub Clean_Direct_paragraph()
'
' Delete direct formatting to paragraph
'
'
Selection.ClearParagraphDirectFormatting
End Sub
All of them works nicely, unless I try to select all footnotes in a document, where it complain that I am crossing the boundaries :D I was thinking about a loop that select each story range, but all examples I could find had some kind of find and ranges and the ClearFormatting methods where not available. So far my code is
Sub Cleanup()
Dim Rng As Range
For Each Rng In ActiveDocument.StoryRanges
With Rng
With Selection.Range
Selection.ClearCharacterDirectFormatting
Selection.ClearParagraphDirectFormatting
End With
End With
Next
End Sub
But I see it is not working at all and I am stuck. As a side note, ClearCharacterDirectFormatting is not clearing highlighted text.
EDIT: I have started to create some If clause to figure out how to select the text of each endnote or footnote for selection, but I seem unable to grab the proper object. I commented out the ElseIf statement because it is complaining about using wrong methods
Sub Cleanup()
For Each myStory In ActiveDocument.StoryRanges
If myStory.StoryType = wdMainTextStory Then
myStory.Select
Selection.ClearCharacterDirectFormatting
Selection.ClearParagraphDirectFormatting
Selection.Collapse
' ElseIf myStory.StoryType = wdEndnotesStory Then
' For Each myEndnote In myStory.Endnotes
' myEndnote.Text.Select
' Selection.ClearCharacterDirectFormatting
' Selection.ClearParagraphDirectFormatting
' Next myEndnote
' ElseIf myStory.StoryType = wdFootnotesStory Then
' For Each myFootnote In myStory.Footnotes
' myFootnote.FormattedText.Select
' Selection.ClearCharacterDirectFormatting
' Selection.ClearParagraphDirectFormatting
' Next myFootnote
End If
Next myStory
End Sub
This is the general idea so far.