在 vba 中设置工作簿主题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5896493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
setting workbook themes in vba
提问by Alex Fisher
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?
有谁知道我如何创建一个新的工作簿并将工作簿主题 = 设置为当前工作簿,有没有办法做到这一点,类似于你如何设置颜色,即 ActiveWorkbook.Colors = ThisWorkbook.colors(我相信你可以仍然在 excel 2007 中执行此操作,因此这将是我的解决方法,但我更愿意设置整个主题)。我需要创建一个工作簿并设置工作簿主题,而不使用文件路径,即没有将主题保存在所有用户 PC 上。这可能吗?
Thank you ever so much to anybody who can help with this one! :-)
非常感谢任何可以帮助解决这个问题的人!:-)
回答by Vikas
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 :
您无法设置工作簿的主题属性,因为它是只读属性。我会执行以下操作来复制 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