activate macro

P

Patrick

how do i automatically run a macro when i move from one worksheet to another.

ie select another worksheet, then automatically run a specific macro


pat
 
E

Earl Kiosterud

Patrick,

Put this sub in the ThisWorkbook module. Sh will be the worksheet that was just activated.

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
MsgBox Sh.Name
' take out the line above and put in your code
End Sub

--
Earl Kiosterud
www.smokeylake.com

Note: Top-posting has been the norm here.
Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
 
G

Gord Dibben

Private Sub Worksheet_Activate()
macroname
End Sub

This is sheet event code and goes into the sheet module of whichever sheet is be
activated for the macro to run.


Gord Dibben MS Excel MVP
 
D

Don Guillett

right click sheet tab>view code>left window select worksheet>right window
select sheet activate.
 
P

Patrick

cheers
works a treat.

programmming in access is so much easier than excell.



but unfortunately am having to use it


pat
 
P

Patrick

thanks


pat


Earl Kiosterud said:
Patrick,

Put this sub in the ThisWorkbook module. Sh will be the worksheet that was just activated.

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
MsgBox Sh.Name
' take out the line above and put in your code
End Sub

--
Earl Kiosterud
www.smokeylake.com

Note: Top-posting has been the norm here.
Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
 
Top