PDA

View Full Version : Change the Background Color of button added to worksheet using vba



k13r4n
03-10-2009, 02:14 PM
hi all, hopefully this is a quick one

part of a macro i have writen imports some data from a .csv file into excel and formats that data over 2 sheets, ive got the vba to add a series of buttons to sheet one, only snag is i cant work out how to set the background color of the button, ive worked out how to change all the text formating but not the button color, code below


For l = ButtonStart To ButtonFinish

Range("G" & 8 + (12 * l)).Activate
CellX = ActiveCell.Left
CellY = ActiveCell.Top
CellH = ActiveCell.Height
CellW = ActiveCell.Width
ActiveSheet.Buttons.Add(CellX, CellY, CellW, CellH + 3).Select
Selection.Name = "Data" & l
Selection.OnAction = "GotoData"
Selection.Characters.Text = "View Data"
Selection.Font.ColorIndex = 45
Selection.Font.Bold = True

Next


all im missing is one line that sets the background color to ColorIndex 56 (grey-80%) and i cant work out the proper way to set it.

Google failed me :(


thanks

:beerchug:

mdmackillop
03-10-2009, 02:28 PM
I don't believe you can change the colour of a Forms button. Look at ActiveX buttons, they have a BackColor property.

k13r4n
03-10-2009, 02:53 PM
thanks, will have a look

kieran