Thread: Control Names
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary L Brown Gary L Brown is offline
external usenet poster
 
Posts: 219
Default Control Names

I THINK I understand what you are looking for.
Here's an example of a command button called 'cmdMON'.

The code behind the command button would be...
'/============================================/
Private Sub cmdMon_Click()
'passing a part of the command button's name
' to another subroutine that will show that
' name in a messagebox
Call TestName1(Right(Me.cmdMon.Name, 3))

'passing a part of the command button's name
' to another subroutine that will use the
' name to call a concatenated subroutine
Call TestName2(Right(Me.cmdMon.Name, 3))
End Sub
'/============================================/

In a REGULAR CODE Module....
'/============================================/
Public Sub TestName1(strName As String)
'This macro can be in the form or a regular code module
MsgBox strName
End Sub
'/============================================/
Public Sub TestName2(strName As String)
'concatenates 2 strings to run a macro
'this macro MUST be in a REGULAR CODE MODULE
' otherwise the 'Run' method will fail
Application.Run "Test" & strName
End Sub
'/============================================/
Public Sub TestMon()
'called from the concatenations in Sub TestName2
'this macro MUST be in a REGULAR CODE MODULE because
' TestName2 is in a regular code module
'It does NOT have to be in the same module
MsgBox "This is a test of running a macro " & _
"from concatenated strings."
End Sub
'/============================================/

HTH,
--
Gary Brown

If this post was helpful, please click the ''Yes'' button next to ''Was this
Post Helpfull to you?''.


"Graham Y" wrote:

Hi
I have a form for weekly input of data with lots of controls ending in the 3
letter day (ie Mon Tue etc), can I pass those 3 letters to a sub and then
concatenate them to the rest of the control name so I don't have to have a
sub for each day?

TIA