Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Excel 2003
On my UserForm I have several CommandButtons. In my code, I want to refer to a selected or active one as a variable, rather than by it's name, say CommandButton4. So I store it's name:- Worksheets("MyVariables").Range("A4")=UserForm1.Ac tiveControl.Name (which works ok) and instead of UserForm1.CommandButton4.BackColor = ................. I would like to do:- UserForm1.Worksheets("MyVariables").Range("A4").Ba ckColor = .................. which doesn't work, as the synyax or method is wrong. Can it be done and if so how. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Put a CommandButton on a Userform, paste the following into the form code.
Ensure the activeworkbook has a sheet named "Sheet1" (the sheet doesn't need to be active). Press F5 to run the form. Private Sub UserForm_Activate() Dim sCtrName As String Dim nClr As Long With ActiveWorkbook.Worksheets("Sheet1") .Range("A4").Value = "CommandButton1" .Range("B4").Value = RGB(123, 234, 56) '''maybe a system colour '.Range("B4").Value = vbInactiveTitleBar sCtrName = .Range("A4").Value nClr = .Range("B4").Value End With Me.Controls(sCtrName).BackColor = nClr End Sub Regards, Peter T "donwb" wrote in message ... Excel 2003 On my UserForm I have several CommandButtons. In my code, I want to refer to a selected or active one as a variable, rather than by it's name, say CommandButton4. So I store it's name:- Worksheets("MyVariables").Range("A4")=UserForm1.Ac tiveControl.Name (which works ok) and instead of UserForm1.CommandButton4.BackColor = ................. I would like to do:- UserForm1.Worksheets("MyVariables").Range("A4").Ba ckColor = ................. which doesn't work, as the synyax or method is wrong. Can it be done and if so how. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Many thanks Peter T.
Tat worked. donwb "Peter T" <peter_t@discussions wrote in message ... Put a CommandButton on a Userform, paste the following into the form code. Ensure the activeworkbook has a sheet named "Sheet1" (the sheet doesn't need to be active). Press F5 to run the form. Private Sub UserForm_Activate() Dim sCtrName As String Dim nClr As Long With ActiveWorkbook.Worksheets("Sheet1") .Range("A4").Value = "CommandButton1" .Range("B4").Value = RGB(123, 234, 56) '''maybe a system colour '.Range("B4").Value = vbInactiveTitleBar sCtrName = .Range("A4").Value nClr = .Range("B4").Value End With Me.Controls(sCtrName).BackColor = nClr End Sub Regards, Peter T "donwb" wrote in message ... Excel 2003 On my UserForm I have several CommandButtons. In my code, I want to refer to a selected or active one as a variable, rather than by it's name, say CommandButton4. So I store it's name:- Worksheets("MyVariables").Range("A4")=UserForm1.Ac tiveControl.Name (which works ok) and instead of UserForm1.CommandButton4.BackColor = ................. I would like to do:- UserForm1.Worksheets("MyVariables").Range("A4").Ba ckColor = ................. which doesn't work, as the synyax or method is wrong. Can it be done and if so how. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Passing variable values to userform control | Excel Discussion (Misc queries) | |||
Selecting control on userform with part of control name (set question) | Excel Programming | |||
Control Sequence from Userform Control | Excel Programming | |||
Problem with references to OCX control | Excel Programming | |||
External data references in a userform control | Excel Programming |