Skip to content

Instantly share code, notes, and snippets.

@darth-veitcher
Created December 6, 2016 08:24
Show Gist options
  • Save darth-veitcher/20148581e2e6c8d73994a765f4bac8c0 to your computer and use it in GitHub Desktop.
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
' 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