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?
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?
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.
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)
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
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
Thank you everyone for your input. Paul, thanks for the code. It did the job.