John Walkenbach Colour Palette

E

ExcelMonkey

I am trying to integrate John Walkenbachs colour palette
routine into a marco that I have written.

http://www.j-walk.com/ss/excel/tips/tip49.htm

I am trying to use it with a form that has multiple
buttons on it. I want to be able to call the colour
palette from multiple buttons. That is, each button is
essentially a colour option button. I then want the
button that is clicked to take the colour of the palette
colour chosen.

The snippet below from the JW code below shows how he
takes the colour chosen from the palette and then uses it
to colour a shape called "donut".

I know I can simply call the main sub from each button
click event. However as I have to also ensure that the
sub below knows which button to colour, I am assuming
that this may entail some other coding for the separate
buttons. Does the coding for the buttons need to go into
a Class Module?

Thanks


'Sub Test_GetAColor1()
'' Example of using the GetAColor function
'' This sub prompts for a color, then changes
'' the color of a shape named Donut
Dim UserColor As Long
Dim OldSelection As Object
Set OldSelection = Selection
UserColor = GetAColor()
If UserColor <> False Then
ActiveSheet.Shapes("Donut").Select
Selection.ShapeRange.Fill.ForeColor.RGB =
UserColor
Selection.ShapeRange.Line.ForeColor.RGB =
UserColor
OldSelection.Select
End If
End Sub
 
T

Tom Ogilvy

You could use a class module, but unless you have a huge number of buttons,
you can just have the click event call a common procedure (ColorABtn)
passing in its identify (which you provide for in the click event).

Private Sub CommandButton1_Click()
Dim btn as MSForms.CommandButton
set btn = me.Controls("CommandButton1")
ColorABtn btn
End Sub

Private Sub CommandButton2_Click()
Dim btn as MSForms.CommandButton
set btn = me.Controls("CommandButton2")
ColorABtn btn
End Sub

Sub ColorABtn(btn as MSForms.CommandButton)
Dim UserColor As Long

UserColor = GetAColor()
If UserColor <> False Then
btn.BackColor = ColorValue
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top