Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default UserForm Control references as variable

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default UserForm Control references as variable

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default UserForm Control references as variable

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing variable values to userform control KJ-clueless Excel Discussion (Misc queries) 2 November 27th 07 10:51 PM
Selecting control on userform with part of control name (set question) Keith Excel Programming 4 January 10th 07 02:24 PM
Control Sequence from Userform Control Nigel Excel Programming 3 December 29th 04 01:25 PM
Problem with references to OCX control Senapathy Excel Programming 0 July 20th 04 11:12 AM
External data references in a userform control jmikerea[_3_] Excel Programming 2 July 17th 04 01:11 PM


All times are GMT +1. The time now is 12:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"