How to call a public module macro in private module macro

rinijg

New Member
Joined
May 13, 2011
Messages
47
Hi,

I have a private module macro

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$E$1" Then
Run "presence()"
End If
End Sub

But the macro presence is in "this worksheet" modulw

how should i call the macro presence??
Please help me
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Do you mean it's in the ThisWorkbook module? If so, why is it not in a normal module if you need to call it from other routines?
 
Upvote 0
ok..let me make myself clear...
i have a macro called presence in "this worksheet" module.
the basic idea of this code is as follows. i have a dropdown menu in sheet1 cell E1, which contains names of some machine. when i select one machine name from that, i want the macro presence to run(this macro has all the calculations related to a machine).
for this i put the following code in the module of sheet1

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$E$1" Then
Run "presence()"
End If
End Sub

i am not sure if what i did is correct... when i am running it shows the error "presence macro is not define"

i hope you got my confusion..
thanks a lot:)
 
Upvote 0
There is no "this worksheet" module. If you mean the same sheet module as your event code, then just use
Code:
presence
or:
Code:
Call presence
 
Upvote 0
oh!!!! i am really sorry.. thats "this workbook module"
the presence code is in "this workbook" module and the other code is in sheet 1 module..
really sorry for the mistake:(
 
Upvote 0
In worksheet's module:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.Run "ThisWorkbook.Presence"
End Sub

In ThisWorkbook:
Code:
Sub Presence()
    MsgBox "I was found :-)"
End Sub

@Rory:
This seems nutty to me. I made the Sub 'Presence' Private and it still ran. Why?
 
Upvote 0
@rinijg:

Sorry, I forgot to mention that I certainly would have the called sub in a standard module.
 
Upvote 0
Application.Run has no sense of privacy. ;)
 
Upvote 0
Thanks Rory. Slow fingers here, I was trying to edit, as had just found a couple of threads. Sigh... I think I actually knew that at one point; too many brain cells leaking out somewheres...

I like the way you put it:grin:
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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