ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro name as constant (https://www.excelbanter.com/excel-programming/278981-macro-name-constant.html)

Jamie Martin[_2_]

Macro name as constant
 
Can I use a constant in declaring the name of a Sub procedure? Better yet
(so my Sub procedures can continue to have descriptive names), can a
procedure output its own name as a string?

I ask because I have many verbose message boxes that refer to the names of
the macros that a user has invoked or that the invoked macro has called, and
I want to make sure I get the names of the macros right every time.



Bernie Deitrick[_2_]

Macro name as constant
 
Jamie,

It's easier to just use declared constants:

Sub TestMacro()
Const myName As String = "TestMacro"
MsgBox "The macro " & myName & " has worked.", _
vbOKOnly, "Message from " & myName
End Sub

HTH,
Bernie


"Jamie Martin" wrote in message
...
Can I use a constant in declaring the name of a Sub procedure?

Better yet
(so my Sub procedures can continue to have descriptive names), can a
procedure output its own name as a string?

I ask because I have many verbose message boxes that refer to the

names of
the macros that a user has invoked or that the invoked macro has

called, and
I want to make sure I get the names of the macros right every time.





Chip Pearson

Macro name as constant
 
Jamie,

Unfortunately, there is no way to get programmatically the name of the
currently executing procedure. You can, of course, hard code the name of the
procedure within each macro, and some 3-party tools can automate this (e.g.,
MZ-Tools), but in the end, the name is hard coded.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com


"Jamie Martin" wrote in message
...
Can I use a constant in declaring the name of a Sub procedure? Better yet
(so my Sub procedures can continue to have descriptive names), can a
procedure output its own name as a string?

I ask because I have many verbose message boxes that refer to the names of
the macros that a user has invoked or that the invoked macro has called,

and
I want to make sure I get the names of the macros right every time.





Jamie Martin[_2_]

Macro name as constant
 
Yeah, that's a good trick. Much easier to maintain. Thanks.

"Bernie Deitrick" wrote in message
...
Jamie,

It's easier to just use declared constants:

Sub TestMacro()
Const myName As String = "TestMacro"
MsgBox "The macro " & myName & " has worked.", _
vbOKOnly, "Message from " & myName
End Sub

HTH,
Bernie


"Jamie Martin" wrote in message
...
Can I use a constant in declaring the name of a Sub procedure?

Better yet
(so my Sub procedures can continue to have descriptive names), can a
procedure output its own name as a string?

I ask because I have many verbose message boxes that refer to the

names of
the macros that a user has invoked or that the invoked macro has

called, and
I want to make sure I get the names of the macros right every time.








All times are GMT +1. The time now is 12:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com