View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default 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 *