2

I currently have a userform that loads up with three command buttons (primary, secondary and tertiary). The idea here is that a user will select their own colour scheme using these three buttons.

I have cells in my workbook that represent each colour and then a macro which sets all chart objects to these colours (using the cells) when it is run.

I have managed to initialise the userform so that the three command buttons interior colour is determined by the three cells in my workbook:

Private Sub UserForm_Initialize()

Dim cs As Worksheet
Set cs = Sheets("ColourScheme")

TextBox1.SetFocus '' Shift focus away from primary

Primary.BackColor = cs.Range("B1").Interior.color
Secondary.BackColor = cs.Range("B2").Interior.color
Tertiary.BackColor = cs.Range("B3").Interior.color

End Sub

What I want to do now is that when each button is clicked, the colour palette loads up, the user selects a colour either using the wheel or an RGB figure and then finally the cells in my workbook and the command buttons interior colour change based on the user's choice.

I don't know if this can be done but so far I'm having no luck with anything I've tried to load the palette up:

Private Sub Primary_Click()

Application.Dialogs.Item(xlDialogColorPalette).Show

End Sub
1
  • Sorry @ShaiRado I haven't tried it. Managed to work out my own solution before I checked yours. Thanks though. Commented Aug 31, 2016 at 14:30

2 Answers 2

2

Try the function which I use on several Applications, it's slightly converted to fit your original minimalized code, let me know if it works for you...

Private Sub Primary_Click()

Const ColorIndexLast                As Long = 32       'index of last custom color in palette
Dim PickNewColor                    As Double          'color that was picked in the dialogue
Dim myOrgColor                      As Double          'original color of color index 32

'save original palette color,modify Range according to your needs
myOrgColor = Range("A1").Interior.Color

'call the color picker dialogue
If Application.Dialogs(xlDialogEditColor).Show(ColorIndexLast) = True Then

    ' "OK" was pressed, read the new color from the palette
    PickNewColor = ActiveWorkbook.Colors(ColorIndexLast)
    ActiveWorkbook.Colors(ColorIndexLast) = myOrgColor  ' reset palette color to its original value
Else
    ' "Cancel" was pressed, palette wasn't changed >> return old color (or xlNone if no color was passed to the function)
    PickNewColor = myOrgColor
End If

' update Colors in relevant Cell
Range("A1").Interior.Color = PickNewColor

End Sub
Sign up to request clarification or add additional context in comments.

Comments

0

This is the solution I arrived at:

Private Sub Primary_Click()

Dim cs As Worksheet
Set cs = Sheets("ColourScheme")

Dim newColour As Long

Application.Dialogs(xlDialogEditColor).Show (1)

newColour = ThisWorkbook.Colors(1)

cs.Range("B1").Interior.color = newColour

Primary.BackColor = newColour

End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.