VBA to change taskbar colour

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,926
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
This thread shows how it's possible to change the theme using VBA:

Code:
https://www.mrexcel.com/board/threads/change-office-theme-with-code.1260031/page-2#post-6190667

@Jaafar Tribak provided a nice solution.


I would like to know if it is possible to "extend" this idea.

Manually, the steps would be:

Code:
Settings -> Personalisation -> Choose your mode -> Dark

and that changes the taskbar to black.

Is this possible to replicate using VBA?

Thanks
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Why? You should not be changing a user's settings in your code as a rule.
 
Upvote 0
Why? You should not be changing a user's settings in your code as a rule.
I want to give my users the option of changing the colours, so if dark is chosen, the entire screen is black, including the taskbar.

Having said that, I definately am not interested in a solution that requires changing the registry.
 
Upvote 0
Than I think you're out of luck. You're trying to change Windows settings, not Office ones.
 
Upvote 0
As mentioned, changing the windows settings is disapproved of and dangerous. Setting the composition attributes of the "Shell_TrayWnd" window (using dwmapi.dll & uxtheme.dll) yields some results w/o affecting the windows settings globally ... Unfortunately, the code (and resulting color) is not guaranteed to work from one Windows edition to another and from one build to another. Microsoft keep insisting on changing/restricting how to personalize windows.

I have some code that worked for setting the taskbar color in Win7 but it no longer works in Win10.

Which version of windows do you have?
 
Upvote 0
As mentioned, changing the windows settings is disapproved of and dangerous. Setting the composition attributes of the "Shell_TrayWnd" window (using dwmapi.dll & uxtheme.dll) yields some results w/o affecting the windows settings globally ... Unfortunately, the code (and resulting color) is not guaranteed to work from one Windows edition to another and from one build to another. Microsoft keep insisting on changing/restricting how to personalize windows.

I have some code that worked for setting the taskbar color in Win7 but it no longer works in Win10.

Which version of windows do you have?
I'm using Windows 11.
 
Upvote 0
I'm using Windows 11.
Sorry. I have Win10.

Edit:
If you just want this because the taskbar color clashes with the application when in dark mode, you could (programmatically) temporarly hide the taskbar and restore it when done... but then again, this will alter the user taskbar settings.
 
Last edited:
Upvote 0
Sorry. I have Win10.

Edit:
If you just want this because the taskbar color clashes with the application when in dark mode, you could (programmatically) temporarly hide the taskbar and restore it when done... but then again, this will alter the user taskbar settings.
Thanks, that would be a workaround.
 
Upvote 0
Thanks, that would be a workaround.
Try this to toggle the Taskbar AutoHide state:

VBA Code:
Option Explicit

Private Type PAPPBARDATA
    cbSize As Long
    #If VBA7 Then
        hwnd As LongPtr
    #Else
        hwnd As Long
    #End If
    Bytes(0& To 23&) As Byte
    lParam As Long
End Type

#If VBA7 Then
    Private Declare PtrSafe Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As PAPPBARDATA) As LongPtr
    Private Declare PtrSafe Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
#Else
    Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As PAPPBARDATA) As Long
    Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If

Sub ToggleTaskBarAutoHide()
    #If Win64 Then
        Const NULL_PTR = 0^
    #Else
        Const NULL_PTR = 0&
    #End If
    Const ABM_GETSTATE = &H4, ABM_SETSTATE = &HA
    Const ABS_ALWAYSONTOP = &H2, ABS_AUTOHIDE = &H1
    Dim uData As PAPPBARDATA    
    With uData
        .hwnd = FindWindow("Shell_TrayWnd", vbNullString)
        .cbSize = LenB(uData)
        If SHAppBarMessage(ABM_GETSTATE, uData) = NULL_PTR Then
            .lParam = ABS_AUTOHIDE
        Else
            .lParam = ABS_ALWAYSONTOP
        End If
        Call SHAppBarMessage(ABM_SETSTATE, uData)
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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