Change the Office Theme via VBA with RegEdit

frabulator

Active Member
Joined
Jun 27, 2014
Messages
250
Office Version
  1. 2019
Platform
  1. 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:

NameValueDescription
msoNotThemeColor0Specifies no theme color.
msoThemeColorAccent15Specifies the Accent 1 theme color.
msoThemeColorAccent26Specifies the Accent 2 theme color.
msoThemeColorAccent37Specifies the Accent 3 theme color.
msoThemeColorAccent48Specifies the Accent 4 theme color.
msoThemeColorAccent59Specifies the Accent 5 theme color.
msoThemeColorAccent610Specifies the Accent 6 theme color.
msoThemeColorBackground114Specifies the Background 1 theme color.
msoThemeColorBackground216Specifies the Background 2 theme color.
msoThemeColorDark11Specifies the Dark 1 theme color.
msoThemeColorDark23Specifies the Dark 2 theme color.
msoThemeColorFollowedHyperlink12Specifies the theme color for a clicked hyperlink.
msoThemeColorHyperlink11Specifies the theme color for a hyperlink.
msoThemeColorLight12Specifies the Light 1 theme color.
msoThemeColorLight24Specifies the Light 2 theme color.
msoThemeColorMixed-2Specifies a mixed color theme.
msoThemeColorText113Specifies the Text 1 theme color.
msoThemeColorText215Specifies 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
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
as an update I have tweaked the code a little. I noticed an error in my previous where I was writing a string when it needed to be a dword.

VBA Code:
Sub TestChange()
    ChangeThemeColor 3
    
End Sub

Public Sub ChangeThemeColor(Val As Long)
    RegLocation = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\" & application.Version & "\Common\"
    Dim myRegKey As String
    myRegKey = RegLocation & "UI Theme"
    Dim myWS As Object
    'access Windows scripting
    Set myWS = CreateObject("WScript.Shell")
    'write registry key
    myWS.RegWrite myRegKey, Val, "REG_DWORD"
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,103
Messages
6,123,106
Members
449,096
Latest member
provoking

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top