Consulting

Results 1 to 9 of 9

Thread: VBA to remove all Character Styles but keep formatting

  1. #1

    VBA to remove all Character Styles but keep formatting

    Hello,

    I have a macro that removes all Character Styles from the body of the document but I would like to keep the superscript that was in the Footnote Reference character style as well as the formatting that is in other character styles. Ideally I would like the macro to remove character styles from the actual footnotes at the bottom of the pages not just in the body of the document. Any help is greatly appreciated!

    This is my code:
    Selection.WholeStory
    On Error Resume Next
    Selection.ClearCharacterStyle
    On Error GoTo 0

    Thanks,
    Bernadette

  2. #2
    I can accomplish getting rid of the Footnote Reference character style and replacing it with superscript by doing what you see below. However I need a macro to automate this.


    1. Select the first footnote reference in the body of the document
    2. Home, Editing, Select, Select Text with similar formatting
    3. Ctrl spacebar
    4. Home, Font, click Superscript

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,217
    Location
    Bernadette, Since you know the steps, have you tried recording a macro doing just exactly that?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    Yes I did try recording the macro by recording the steps but it didn't work.

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,217
    Location
    I would have thought one of the word guru's might have been here by now. Since they haven't, have you had a look at this thread https://www.msofficeforums.com/word/...ormatting.html
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    Thanks but I don't want to save it as an RTF, as I would lose a lot of formatting.

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,771
    Location
    Why do you want to delete the Style but keep the formatting?

    It seems to me that the final result would look the same, but Styles are one of Word's most useful and powerful features
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    The character styles are causing problems when the document is published on a different platform. Sometimes the text disappears or has weird text appear. It looks like I won't be getting an answer here so I will have to live with it. Thanks to everyone who replied.

  9. #9
    I was able to get it to work except it does not put the superscript back into the footnote reference number at the bottom of the page but it now deletes character styles both in the body and in the footnote text of the document. Here is the code:

    Sub DeleteFootnoteReferenceCharacterStyle()
        ' Delete footnote reference character style and replace with superscript font in the body of the document
        Selection.Find.ClearFormatting
        Selection.Find.Style = ActiveDocument.Styles("Footnote Reference")
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find.Replacement.Font
            .Bold = False
            .SmallCaps = False
            .AllCaps = False
            .Superscript = True
        End With
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        ActiveDocument.Styles("Footnote Reference").Delete
        '  Delete all character styles in the body of the document and in footnotes
        Dim aStl As Style
        On Error Resume Next
        For Each aStl In ActiveDocument.Styles
            If aStl.Type = wdStyleTypeCharacter Then
                ActiveDocument.Styles(aStl).Delete
            End If
        Next aStl
    End Sub
    Last edited by Aussiebear; 08-10-2024 at 03:11 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •