VBA Code To Retrieve Current Running Macro Name

jochryem

New Member
Joined
Apr 6, 2018
Messages
3
Hi,

I'm trying to find VBA code that will tell me the name of the current macro that is running.

Example: Sub MyMacroName()

Dim MacroName As String

MacroName = HowDoIGetMyMacroName
MsgBox MacroName

End Example:

Does anyone know if code exists to do this?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Welcome to the Board!

I believe that you can only run one macro at a time, so I don't think something like this could work.

Why not just but Message Boxes at the beginning/end of your macros that same something like?
"Macro1 has started running"
"Macro1 is finished running"


Or perhaps look at using a Status Bar (if you search the forum or do a Google Search, there are many articles on how to do these).
 
Last edited:
Upvote 0
I'm trying to use the macro name to join as a part of another sub procedure so that I can duplicate the procedure across multiple modules and workbooks so that I don't have to hard-code the call to the sub procedure name each time as it requires it to be unique
 
Upvote 0
so that I can duplicate the procedure across multiple modules and workbooks
Why would you need to duplicate it across multiple modules and workbooks?
Any procedure you write can be written to run across multiple worksheets and/or workbooks.
 
Upvote 0
I don't believe that's possible. Why do you need to know? There may be other solutions ...

WBD
 
Upvote 0
I have code that updates multiple reports from a SQL server (ie: Report A, Report B, Report C and so on). I have a module that is unique for each report and I call sub procedures within each module (a save as macro). There is a ton going on in these modules so I'm trying to simplify it so that it is easier to duplicate (less maintenance) as I have hundreds of reports that get pulled from the SQL server.
 
Upvote 0
Here is another option that may work for you that I have seen people do.
Create a log file, and have each macro write to the log file, writing the name of the Macro running and the date/time it started.
Then, you can refer to the log file at anytime to see where it is in the process.
 
Upvote 0
You could have a global variable in a module:

Code:
Public currentMacroName As String

Then set it at the start of each macro as appropriate:

Code:
Public Sub MyMacro()

currentMacroName = "MyMacro"

...

End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top