Call "Private" Macro From Different Module

JerryD

New Member
Joined
Dec 23, 2005
Messages
21
Is it possible to call a "Private" Sub (located on one module sheet) from a sub located on a different module sheet? (see Ex below and conditions). The conditions are that the Sub must remain "Private" and the two subs remain on different module sheets (I know it will work if the sub is Public). Tks.

'(Example: Private Sub DoSomething is On sheet "Module1")
Private Sub DoSomething()
' code
End Sub

'(Then On sheet "Module2")
Sub AlsoDoSomething()
' Can't get the following line of code to work
Call DoSomething
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Jerry

Why must the sub remain private?

Anyway, try this.
Code:
'(Then On sheet "Module2")
Sub AlsoDoSomething()
' Can't get the following line of code to work
Application.Run "DoSomething"
End Sub
 
Upvote 0
That's a tall order. Considering what the Help item says that Private means (for subs), real tall :rolleyes:

You might consider using "Friend" instead of "Private"

I tested application.run in two modules, and the Private one was not recognized. BTW you said "sheets" but it seemed you meant modules.
 
Upvote 0
Hey Gates

You kinda look familiar. You're right, I did mean module - I think that at one time, you could have modules as sheets in your workbook. Anyway...

I tried Application.Run on my machine and it works OK (Excel2000). I have seen some of the responders in this group mention that responses would work on one version of Excel but not on other versions of Excel. What version of Excel do you have that Application.Run "does not" run on?
(I'm completely ignorant here and would just like to know)
 
Upvote 0
"Real" Scope experts, please step in on this:

Under XL03 (Excel version 11),
I created a new Module2. I pasted the name of a private sub called MySub which is in Module1. Module2 then shows
Sub foo()
Application.Run mySub
End Sub

Now, running it does nothing with MySub. A real giveaway is if you left click on the word MySub, then hit Shift-F2, it thinks MySub does not exist.
 
Upvote 0
Gates

Where are the quotes around mySub?:)
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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