If you end up with a workbook that contains custom styles, removing all of these may be a pain depending on how many there are.
With a little VBA we can easily list and delete all custom styles.
In my workbook I have three custom styles, Cool Style 1, Gaudy Style and Sunglasses Required.
The first routine I've written is called List_All_Styles
Download the Example Workbook
All of the VBA code I use in this post is in the example workbook. Download it and use it yourself.
Enter your email address below to download the workbook.
By running this we get, not surprisingly, a list of styles in the workbook, and custom created styles are marked as such.
If there are only a handful of custom styles you can delete them by hand, but if there are lots just run Delete_Styles to get rid of them.
A Note on Looping in VBA
You may have noticed that the For loop that deletes the styles is counting down, rather than up, which you might normally expect.
This is because when the For loop is started the value of Styles.count is set to however many styles there are.
Let's say it is set to 5, so our loop will execute 5 times, from 1 to 5.
If during this loop we delete a style, the number of styles in the workbook decreases to 4. But we've told our loop to execute 5 times.
When it tries to execute for the 5th time the .Styles(counter) reference is invalid because counter is 5 but there isn't a 5th style in the workbook now because we deleted one. VBA will generate an error here.
In scenarios like this you need to start the For loop counting down from the number of styles in the workbook (.Styles.count) to 1.
That way, if your code deletes a style, .Styles(counter) won't try accessing a style that does not exist.