Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default 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.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default 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.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default 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.






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
Need Help Creating a Macro to Multiply Cells by a Constant Number Tyn Excel Discussion (Misc queries) 5 February 12th 07 10:40 AM
Constant loan payments vs. constant payments of principal lalli945 Excel Worksheet Functions 3 December 20th 06 10:33 PM
Constant sedonovan Excel Discussion (Misc queries) 5 June 23rd 06 11:43 AM
Reading a VBA constant value by an outsider macro? Tom Ogilvy Excel Programming 1 September 7th 03 05:57 PM
Reading a VBA constant value by an outsider macro? Chip Pearson Excel Programming 1 September 7th 03 12:13 PM


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

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

About Us

"It's about Microsoft Excel"