Home » excel » excel – setting workbook themes in vba

excel – setting workbook themes in vba

Posted by: admin May 14, 2020 Leave a comment


Does anybody know how I can create a new workbook and set the workbook theme = to the current workbook, is there a way to do this, similar to how you set the color, i.e. ActiveWorkbook.Colors = ThisWorkbook.colors (I believe you can still do this in excel 2007, so this will be my workaround, but I would prefer to set the whole theme). I need to create a workbook and set the workbook theme, without using a filepath, i.e. without having the theme saved on all user pc’s. Is this possible?

Thank you ever so much to anybody who can help with this one! 🙂

How to&Answers:

There is no way you can set the theme property of the workbook as it is a read only property. I would do something like following to copy the colortheme :

Private Sub CopyTheme(baseBook As Workbook, targetBook As Workbook)
Dim themeName As String
themeName = Environ("temp") & "\VBANoobTheme.xml"

'save theme
On Error Resume Next
Kill themeName
On Error GoTo 0
'delete extra sheets
baseBook.Theme.ThemeColorScheme.Save themeName
targetBook.Theme.ThemeColorScheme.Load themeName
End Sub