Running Macro at sheet activation

G

gfkbob

I would like to have a macor run when certain pages are opened. This
is what I have tried...
Private Sub Worksheet_Activate ()
Application.Run "Macroname"
End Sub

All I get is the screen flashing at me about 50 times and the macro
doesn't run.

My hope is to have a macro run on activation and another run on
deactivation. I'm looking for the correct wording. I could sure use
some help. Thanks!
 
G

Guest

If your screen if flashing, then that would be an indication of

1) the macro is running and
2) very poor coding - using recorder style code.

It sounds like your code activates sheets and therefore triggers your event
code to fire over and over in a recursive fashion.


Try it this way

Private Sub Worksheet_Activate ()
On Error goto errHandler
Application.EnableEvents = False
Macroname
errHandler:
Application.EnableEvents = True
End Sub

This is somewhat of a bandaid approach, but should get you going.
 

Ask a Question

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.

Ask a Question

Top