View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Run macro when user selects a different sheet

On top of Mike's response, I'd use:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If sh.Name = "Info" Then
MsgBox "made it to info"
Else
MsgBox "not info"
End If
End Sub

Actually, I'd use:
If lcase(sh.Name) = lcase("Info") Then
just to avoid a difference in upper/lower case.

CraigKer wrote:

I need to run a macro when a user selects a different sheet within my
workbook. I tried using the following code as a test in module 1 with some
other code i wrote:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If ActiveSheet.Name = "Info" Then
MsgBox "made it to info"
Else
MsgBox "not info"
End If
End Sub

However, this does not work. When I change the active sheet in the workbook
nothing happens. Do I need to put this code somewhere else?

Thanks in advance...


--

Dave Peterson