How to get buttons on floating control to pick up colour
Hi
I have created a control with 8 command buttons, for the user to be able
to quickly format cells according to the background colour and font
colour of the button clicked.
I want to be able to pick up the colours and a caption from a setup
sheet, but it isn't working.
The first 4 buttons are selecting the colours set for the last 4, and
the last 4 are left unaltered.
No captions are being picked up to display on each button.
Any clues as to what I am doing wrong - I have been going round in
circles all morning, and can't see the error.
Private Sub Userform_Initialize()
On Error Resume Next
Dim ctrl As Control, btnColors As Long, btn As Long, btnColors2 As
Long, btn2 As Long
Dim vaFore As Variant, vaBack As Variant, vaCapt As Variant
Dim btncaption As String, btncount As Long, i as long
vaBack = Sheets("Colors").Range("E4:E11").Value
vaFore = Sheets("Colors").Range("F4:F11").Value
vacapt = Sheets("Colors").Range("H4:H11").Value
i = 0
btncount = Sheets("Colors").Range("E1").Value 'this counts the
number of cells with values in E4:E11
For Each ctrl In frmcolours2.Controls
If ctrl.Tag = "Color Button" Then
btn = i
btnColors = vaBack(i, 1): btnColors2 = vaFore(i,
1):btnCaption = vaCapt(i,1)
ReDim Preserve Buttons(1 To 8)
Set Buttons(btn).ColorButtons = ctrl
Buttons(btn).ColorButtons.BackColor _
= ThisWorkbook.Colors(btnColors)
Buttons(btn).ColorButtons.ForeColor _
= ThisWorkbook.Colors(btnColors2)
' what need to be inserted here to write the Caption to the
button?
End If
i = i + 1
Next ctrl
End Sub
--
Regards
Roger Govier
|