Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Locating Module for Macro

0

Is there a way to locate where a macro is located (in which Module) that is listed on the Sheet listing in the "Microsoft Excel Objects" listing?

You go to "Visual Basic" and open the "Sheet 1"  in Objects and you see the "Private Sub CommandButton1_Click()" and below that you see the macro assigned to that button,.  Is there any way to trace or find which Module that macro is written in?

Answer
Discuss

Discussion

Orkrj

Please don't forget to respond to the Answers from WillieD24 and me. See below.
John_Ru (rep: 6642) Feb 25, '25 at 7:29 am
Thanks for the help!
orkrj (rep: 16) Feb 25, '25 at 6:07 pm
Wish there was a way to print this...
orkrj (rep: 16) Feb 25, '25 at 6:08 pm
Glad that helped, thanks for selecting my Answer, Orkrj

Not sure what you mean about printing (all browsers allow you to print) but if you want to copy code from an Answer, left click the bar above the code, labelled "Select All" and the code will be copied to your paste buffer as plain text. It can then be pasted into Visual Basic or a text editor etc.
John_Ru (rep: 6642) Feb 26, '25 at 1:25 am
Add to Discussion

Answers

0
Selected Answer

Hi Orkrj.

If your button is placed on Sheet1, then the click macro will be "behind" Sheet1 in Visual Basic.

If (in Design mode) you right-click the button and select "View Code", Visual Basic will show something like:

Private Sub CommandButton1_Click()

End Sub

That is where the code is! You need to write your code there e.g.

Private Sub CommandButton1_Click()
MsgBox "Today's date is " & Format(Date, "dddd mmm dd, yyyy"
End Sub

If you then return to Sheet1 and (out of Design mode) click the button, that code will run.

If however you have existing code in Private Sub CommandButton1_Click that calls another procedure (e.g  called "MyButton") and you don't know where that is:

  1. in the Visual Basic code, select the text MyButton or whatever it's called
  2. in the Visual Basic menu bar, pick Edit/ Find...
  3. in the Find requestor that pops up, click Current Project then FindNext (perhaps more than once)

VB should then locate any places MyButton is used including Sub MyButton() -where the appropriate location e.g. Module1 (rather than Sheet1) will show as greyed in the VB Project window.

Hope this makes sense and helps. If so. please remember to mark this Answer as Selected (or choose WillieD24's Answer if that solves things better).

Discuss
0

 Hello orkrj,

Finding which module just takes 4 simple steps.

1) click on the "View" tab of Excel

2) at the right side double click on "Macros"; this will open a list of all the macros in the workbook

3) in the window that opens select (single click, not double click) the macro you are wanting to know the location of

4) then click either  "Step into" or "Edit"; this will open the module where the macro is stored. You then just need to get the location info from the title bar the module.

If this is the answer you were hoping for please mark my answer as Selected.

Cheers   :-)

Discuss

Discussion

@Willie - it's starting to look like we wasted our time (again). My lack of email notifications continues on the new server but I'm starting to think users are lacking them too. Do you get emails now (other than the "new questions" ones )?
John_Ru (rep: 6642) Feb 25, '25 at 4:41 pm
@John,
Agreed, you would think someone posting a question would be eager to check back to see if it has been answered.
I rarely get an email notification for anything, not even the "new question" email. I check once daily to see if there is anything new.
Cheers   :-)
WillieD24 (rep: 657) Feb 25, '25 at 5:00 pm
@Willie - thanks. Agreed, I'd check for an answer but people do pose the same question on several sites (which is frowned upon by respondents like us). I too check daily, unless I'm too busy on family matters. 
John_Ru (rep: 6642) Feb 25, '25 at 5:40 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login