setting workbook themes in vba
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.开发者_C百科 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! :-)
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
Err.Clear
On Error GoTo 0
'delete extra sheets
baseBook.Theme.ThemeColorScheme.Save themeName
targetBook.Theme.ThemeColorScheme.Load themeName
End Sub
精彩评论