ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Automatically Run a macro when a worksheet is selected (https://www.excelbanter.com/excel-programming/277374-re-automatically-run-macro-when-worksheet-selected.html)

Rob Bovey

Automatically Run a macro when a worksheet is selected
 
"Stephen Hartman" wrote in message
...
Is there a bit of code that will automatically run a macro when I select the
worksheet that contains the macro?

Hi Stephen,

You can use the Worksheet_Activate event, which will fire whenever the sheet
is activated. Note that of the sheet is already active, clicking on its
sheet tab will not cause this event to fire. Place the following event
procedure in the code module behind the worksheet in question and add your
code to it:

Private Sub Worksheet_Activate()
''' Put your code here.
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *




Scott

Automatically Run a macro when a worksheet is selected
 
Hello,

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-----
"Stephen Hartman" wrote in

message
...
Is there a bit of code that will automatically run a

macro when I select the
worksheet that contains the macro?

Hi Stephen,

You can use the Worksheet_Activate event, which will fire

whenever the sheet
is activated. Note that of the sheet is already active,

clicking on its
sheet tab will not cause this event to fire. Place the

following event
procedure in the code module behind the worksheet in

question and add your
code to it:

Private Sub Worksheet_Activate()
''' Put your code here.
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *



.


Tom Ogilvy

Automatically Run a macro when a worksheet is selected
 
http://www.cpearson.com/excel/vbe.htm

--
Regards,
Tom Ogilvy


Scott wrote in message
...
Hello,

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-----
"Stephen Hartman" wrote in

message
...
Is there a bit of code that will automatically run a

macro when I select the
worksheet that contains the macro?

Hi Stephen,

You can use the Worksheet_Activate event, which will fire

whenever the sheet
is activated. Note that of the sheet is already active,

clicking on its
sheet tab will not cause this event to fire. Place the

following event
procedure in the code module behind the worksheet in

question and add your
code to it:

Private Sub Worksheet_Activate()
''' Put your code here.
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *



.





All times are GMT +1. The time now is 09:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com