In its simplest form; rightclick the Sheet tab, choose View Code, paste this in:
Private Sub Worksheet_Activate()
Call MyMacro
End Sub
Sub MyMacro()
MsgBox "Yo"
End Sub
It runs when you click the sheet's tab. If you need this code to run when activating one
of several windows then you also need to program the Workbook_WindowActivate event in
ThisWorkbook module. Post back if that's relevant and troublesome at the same time.
You can (perhaps even should) put MyMacro on a standard module and call it from anything
anywhere. But the activate event must stay where it is. But events code (like Activate)
lives in their spesific modules, here the sheet module.
--
HTH. Best wishes Harald
Followup to newsgroup only please.
Stu said:
Can you run the macro from a module or do you have to run it from that
sheets code?
Thanks
--
Stu
Harald Staff said:
Hi Stu
In its simplest form; rightclick the Sheet tab, choose View Code, paste this in:
Private Sub Worksheet_Activate()
Call MyMacro
End Sub
Sub MyMacro()
MsgBox "Yo"
End Sub
It runs when you click the sheet's tab. If you need this code to run when activating one
of several windows then you also need to program the
I have been trying to add this type of code to a sheet
when the sheet is built using VBA modules. I do not see
how to plug the "Private Sub Worksheet_Activate()" code
onto the new sheet module. I need to have this completly
invisible to the user.
How can we reference the new sheet module programatically?
Any ideas appreciated.
thank you,
Scott
-----Original Message-----
You can (perhaps even should) put MyMacro on a standard
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.