"Renaming Form Buttons From Macro"
How about:
Option Explicit
Private Sub UserForm_Activate()
Dim M As String
Dim A As String
Dim N As Long
For N = 1 To 3
M = "CommandButton" & N
A = Worksheets("sheet1").Range("a" & N).Text
Me.Controls(M).Caption = A
Next N
End Sub
Don wrote:
Hi Gang,
Here's what I've got so far.....I created a test wb and form with three
commandbuttons.....I wish to rename these buttons periodically (only the
caption, not the underlying code), using the contents of cells in Col A. The
msgbox indicates it's stepping through code correctly but, so far, I can only
get it to rename CommandButton1. I've tried all I can think of to get the
code to step through the commandbuttons but so far, nothing works for me.
Private Sub UserForm_Activate()
Dim M As String
Dim A As String
For N = 1 To 3
M = "CommandButton" & N
A = Range("a" & N).Text
MsgBox M
' Me.M.Caption = A<<this didn't work as well as various tries at &
statements.
Me.CommandButton1.Caption = A '<<< this of course only renamed CB1
Next N
End Sub
And and all help here would be greatly appreciated.
TIA,
Don
--
Dave Peterson
|