Created
December 6, 2016 08:24
-
-
Save darth-veitcher/20148581e2e6c8d73994a765f4bac8c0 to your computer and use it in GitHub Desktop.
Delete non-standard styles in target Excel workbook but keep custom styles from host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' Merges styles from Team FP&A into active workbook and deletes all other custom styles | |
| Sub Merge_Styles() | |
| If ActiveWorkbook.Path <> ThisWorkbook.Path Then ' cant be the same file... | |
| Application.EnableEvents = False | |
| Application.DisplayAlerts = False | |
| On Error Resume Next | |
| ' Clear existing custum styles | |
| Dim mpStyle As Style | |
| For Each mpStyle In ActiveWorkbook.Styles | |
| matched = False | |
| If Not mpStyle.BuiltIn Then | |
| For Each s In ThisWorkbook.Styles | |
| If mpStyle = s Then | |
| matched = True | |
| End If | |
| Next | |
| If Not matched Then | |
| mpStyle.Delete | |
| End If | |
| End If | |
| Next mpStyle | |
| ' Apply ours | |
| ActiveWorkbook.Styles.Merge ThisWorkbook | |
| Application.EnableEvents = True | |
| Application.DisplayAlerts = True | |
| End If | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment