Consulting

Results 1 to 5 of 5

Thread: Restoring default Styles in Excel

  1. #1
    VBAX Newbie
    Joined
    Feb 2018
    Posts
    2
    Location

    Restoring default Styles in Excel

    I have an Excel (2010) spreadsheet that has been edited by multiple users and as a result I have a large number of styles that have crept into the spreadsheet. Is there a code that can be run to delete all styles except for the Excel default codes?

  2. #2
    VBAX Regular
    Joined
    Jan 2018
    Posts
    52
    Location
    Hi, dae. You don't need macro to delete unnecessary styles.
    Follow the below instruction.

    1. Right-click a sheet tab, and then click "Select All Sheets" on the shortcut menu.
    2. Right-click a sheet tab again, and then click "Move or Copy".
    3. Select "(new book)" from the "To book:" dropdown list.
    4. Check "Create a copy" box, and click OK.

    The new workbook has only Excel default styles.

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    Ride the wind to the sun
    Posts
    2,594
    back-up your file before testing:

    Sub vbax_61949_restore_default_styles()
         
         Dim styl As Style
         
         On Error Resume Next
         For Each styl In ActiveWorkbook.Styles
             If Not styl.BuiltIn Then styl.Delete
         Next styl
     
     End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,758
    Location
    This is the macro I use to cleanup lots of redundant Styles, HOWEVER I've had workbooks that were so bad (more styles than Excel could handle), the macro wouldn't work and I had to edit the XML to get rid of 40K+ styles. Ugly

    'ALL user defined styles, leaves formatting
    Sub DeleteUserDefinedStyles()
        Dim oStyle As Style
        Dim iStyle As Long
        For iStyle = ActiveWorkbook.Styles.Count To 1 Step -1
            Application.StatusBar = "Checking Style '" & ActiveWorkbook.Styles(iStyle).Name & "'"
            On Error Resume Next
            If Not ActiveWorkbook.Styles(iStyle).BuiltIn Then
                ActiveWorkbook.Styles(iStyle).Delete
            End If
            On Error GoTo 0
        Next
    End Sub
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    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)
    (multiple files can be selected while holding Ctrl key) / 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

  5. #5
    VBAX Newbie
    Joined
    Feb 2018
    Posts
    2
    Location
    Thank you everyone for your input. Paul, thanks for the code. It did the job.

Posting Permissions

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