View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default 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 *



.