+ Reply to Thread
Results 1 to 3 of 3

How to show Theme color window with Excel VBA?

Hybrid View

  1. #1
    Registered User
    Join Date
    03-25-2012
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    Excel 2007
    Posts
    13

    How to show Theme color window with Excel VBA?

    In VBA, I can show color window as below. After selecting a color from this color window, I can use the selected color for changing Font color, Cell background color, etc.

    Application.Dialogs(xlDialogEditColor).Show(10)
    Capture.PNG

    But I want to show below window. Please kindly advise what will be the code and how I can implement in VBA. Let's say I want to color a font with selected color.

    Untitled.png

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,545

    Re: How to show Theme color window with Excel VBA?

    By default, the ExecuteMso method is used to "press" the selected icon, e.g.
    Application.CommandBars.ExecuteMso ("FontColorPicker")
    But in the case of the gallery, the above code will give the font in the active cell the color last selected in the gallery, without showing the color picker.
    Another method to "press" an icon is to use a keyboard shortcut. When you press the left Alt key, you will get prompts as to what keys you need to press sequentially to trigger the icon. In the Polish language version, to display the color picker for fonts, I will use Left Alt, G, F, 1. To color the background of the cells, I will use Left Alt, G, H, 1. In the code below, adjust the key sequence according to your language version.
    Option Explicit
    
    Private Declare Sub keybd_event Lib "User32" _
                                     (ByVal bVk As Byte, _
                                      ByVal bScan As Byte, _
                                      ByVal dwFlags As Long, _
                                      ByVal dwExtraInfo As Long)
    
    
     
    Private Const VK_LMENU = &HA4
    Private Const KEYEVENTF_KEYUP = &H2
    
    
    Sub Test()
      Application.OnTime Now, "TestKbd"
    End Sub
    
    
    Sub TestKbd()
      Call SequenceKeys(VK_LMENU, "G", "F", "1")
    End Sub
    
    
    Sub SequenceKeys(ParamArray vArr() As Variant)
      Dim i As Long
     
      For i = LBound(vArr) To UBound(vArr)
        If TypeName(vArr(i)) = "Integer" Then
          keybd_event vArr(i), 0, 0, 0
          keybd_event vArr(i), 0, KEYEVENTF_KEYUP, 0
        ElseIf TypeName(vArr(i)) = "String" Then
          keybd_event Asc(vArr(i)), 0, 0, 0
          keybd_event Asc(vArr(i)), 0, KEYEVENTF_KEYUP, 0
        End If
      Next i
    End Sub
    If you will be running the macro with a button, you can assign the TestKbd macro to it. If you will be running from the Macro window (keyboard shortcut Alt+F8), then you must call the Test macro. If you will be running this macro with a keyboard shortcut, then the Test macro should at least have this form:
    Sub Test()
      Application.OnTime Now + TimeSerial(0, 0, 1), "TestKbd"
    End Sub
    and all the keys of the applied shortcut must be released before one second expires.

    In theory, you could use the SendKeys method instead of winAPi keybd_event. However, the use of SendKeys on many computers causes a problem (most often the numeric keypad "freaks out") so for many years, however, I have recommended winAPI, which is more stable in execution.

    Artik

  3. #3
    Registered User
    Join Date
    03-25-2012
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to show Theme color window with Excel VBA?

    In my VBA userform, I have command button. I want when user will click in that command button, then below color picker will appear. And when user will select a color then a label in that userform will change the background color.
    Attachment 816307

    With your below code is not showing above color window, even showing nothing. Sorry may be i could not apply in right way. Please help.
    Application.CommandBars.ExecuteMso ("FontColorPicker")
    Currently I am using below code.
    Private Sub CellColorSelLbl_Click()
    On Error Resume Next
    Dim lcolor As Long
    If Application.Dialogs(xlDialogEditColor).Show(10) = True Then
      'user pressed OK
      lcolor = ActiveWorkbook.Colors(10)
     
      CellColorSelLbl.BackColor = lcolor
    Else
      'user pressed Cancel
    End If
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Changing cells to be the theme color?
    By DarkSoul in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 10-20-2020, 01:33 PM
  2. [SOLVED] How to change Theme Color from Accent to ColorIndex
    By Stealth2017 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-01-2018, 02:01 AM
  3. VBA workaround to set workbook color theme
    By Sintek in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-26-2018, 08:51 AM
  4. Replies: 1
    Last Post: 12-07-2016, 08:03 PM
  5. Any way to apply a color theme by changing the color of one cell ?
    By KomicJ in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-02-2016, 01:11 PM
  6. Changing color theme
    By Eashworth in forum Excel General
    Replies: 5
    Last Post: 08-24-2015, 10:59 PM
  7. Replies: 0
    Last Post: 11-30-2009, 01:02 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1