Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
How to programmatically reset a workbook to default styles
Article ID: 291321 - View products that this article applies to.
This article was previously published under Q291321
For a Microsoft Excel 2000 version of this article, see 247933
For a Microsoft Excel 98 version of this article, see 247981
For a Microsoft Excel 97 version of this article, see 247980
For a Microsoft Excel 7.0 version of this article, see 247982
The following Microsoft Visual Basic for Applications Sub procedure removes all styles in a Microsoft Excel workbook, and then adds back the default styles you see in a new workbook. This macro may be helpful for removing extra styles added to a workbook that is infected by a macro virus.
This macro uses the Workbooks.Add method, which bypasses templates in the startup directories. Because of this, it works correctly even if templates in the startup directories have had extra styles added to them.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following macro removes the styles from the currently active workbook. If you type this code into a new workbook, please make sure to activate the workbook from which you want to reset the styles before running the macro.
For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/290140/EN-US/ )How to run sample code from Knowledge Base articles