activate macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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...
 
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
 
right click sheet tab>view code>left window select worksheet>right window
select sheet activate.
 
cheers
works a treat.

programmming in access is so much easier than excell.



but unfortunately am having to use it


pat
 
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...
 
Back
Top