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
 

Some videos you may like

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,047
Office Version
  1. 365
Platform
  1. Windows
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
 

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961
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.
 

JerryD

New Member
Joined
Dec 23, 2005
Messages
21

ADVERTISEMENT

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)
 

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961
"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.
 

JerryD

New Member
Joined
Dec 23, 2005
Messages
21

ADVERTISEMENT

Hey Gates

Put parenthesis around the sub name and see if that is the problem
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,047
Office Version
  1. 365
Platform
  1. Windows
Gates

Where are the quotes around mySub?:)
 

Watch MrExcel Video

Forum statistics

Threads
1,118,109
Messages
5,570,246
Members
412,312
Latest member
linister
Top