frabulator
Active Member
- Joined
- Jun 27, 2014
- Messages
- 256
- Office Version
- 2019
- Platform
- Windows
I have been trying to find a way to change the Office Theme via VBA, however everything I have read online says its not possible.
After some digging I found that the office theme is set in the registry under the following location:
Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Common\UI Theme
Where the values are as follows:
Knowing this, I wrote a code that accesses the value and changes it, but I can not get Excel to refresh and apply the updates. Any ideas on how to make Excel read that the theme has changed in the registry?
After some digging I found that the office theme is set in the registry under the following location:
Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Common\UI Theme
Where the values are as follows:
Name | Value | Description |
---|---|---|
msoNotThemeColor | 0 | Specifies no theme color. |
msoThemeColorAccent1 | 5 | Specifies the Accent 1 theme color. |
msoThemeColorAccent2 | 6 | Specifies the Accent 2 theme color. |
msoThemeColorAccent3 | 7 | Specifies the Accent 3 theme color. |
msoThemeColorAccent4 | 8 | Specifies the Accent 4 theme color. |
msoThemeColorAccent5 | 9 | Specifies the Accent 5 theme color. |
msoThemeColorAccent6 | 10 | Specifies the Accent 6 theme color. |
msoThemeColorBackground1 | 14 | Specifies the Background 1 theme color. |
msoThemeColorBackground2 | 16 | Specifies the Background 2 theme color. |
msoThemeColorDark1 | 1 | Specifies the Dark 1 theme color. |
msoThemeColorDark2 | 3 | Specifies the Dark 2 theme color. |
msoThemeColorFollowedHyperlink | 12 | Specifies the theme color for a clicked hyperlink. |
msoThemeColorHyperlink | 11 | Specifies the theme color for a hyperlink. |
msoThemeColorLight1 | 2 | Specifies the Light 1 theme color. |
msoThemeColorLight2 | 4 | Specifies the Light 2 theme color. |
msoThemeColorMixed | -2 | Specifies a mixed color theme. |
msoThemeColorText1 | 13 | Specifies the Text 1 theme color. |
msoThemeColorText2 | 15 | Specifies the Text 2 theme color. |
Knowing this, I wrote a code that accesses the value and changes it, but I can not get Excel to refresh and apply the updates. Any ideas on how to make Excel read that the theme has changed in the registry?
VBA Code:
Sub TestChange()
ChangeThemeColor 3
End Sub
Public Sub ChangeThemeColor(Val As Long)
RegLocation = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Common\"
Dim myRegKey As String
myRegKey = RegLocation & "UI Theme"
RegKeySave myRegKey, CStr(Val)
End Sub
Sub RegKeySave(i_RegKey As String, _
i_Value As String, _
Optional i_Type As String = "REG_SZ")
Dim myWS As Object
'access Windows scripting
Set myWS = CreateObject("WScript.Shell")
'write registry key
myWS.RegWrite i_RegKey, i_Value, i_Type
End Sub