PDA

View Full Version : Changing several button properties only for the buttons in a list



blukrr
09-05-2012, 07:20 AM
Hey guys,

I'm having some problem with a simple routine.

If had a command button and I wanted to change it's caption I'd use:

CommandButton1.Caption = "Something"


So if I wanted to change the Caption from all of the Button names from a list (like the code below which doesn't work) what would I have to do to make the CurrentCommandButton a CommandButton variable for the property Caption?

For Each CurrentCommandButton In Range("SomeRange") 'SomeRange = A1:A200
CurrentCommandButton.Caption = "Something"
Next CurrentCode


So my goal is to change all of the captions from a list of Button Names.

Thanks in advance.

Kenneth Hobs
09-05-2012, 08:36 AM
Sub NewCommandButtonCaptions()
Dim cell As Range, i As Long
With Worksheets("Sheet1")
For Each cell In .Range("A1", .Range("A" & .Rows.Count).End(xlUp))
i = i + 1
.OLEObjects(cell.Value2).Object.Caption = "Btn" & i
Next cell
End With
End Sub