Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Run macro when user selects a different sheet

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...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Run macro when user selects a different sheet

Hi,

Your code is fine so I guess you have it in the wrong place. It's 'Workbook'
event code so double click 'This Workbook' and paste the code in on the right.

Mike

"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...

  #3   Report Post  
Posted to microsoft.public.excel.programming
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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Run macro when user selects a different sheet

Thanks for the reply.
In my Excel workbook when the VB editor is open it says (Generl) and
Workbook_SheetActive at the top and this is for Module1 (Code). I guess I
don't understand what you mean when you say "double click 'This Workbook' and
paste the code in on the right"?

When I change the active sheet in the workbook by clicking on antoher sheet
nothing happens. Unless the msg box is popping up and closing itself before
I actually see it?


"Mike H" wrote:

Hi,

Your code is fine so I guess you have it in the wrong place. It's 'Workbook'
event code so double click 'This Workbook' and paste the code in on the right.

Mike

"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...

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Selects Directory to Save File Based on Sheet Criteria watchtower Excel Programming 2 August 9th 07 04:08 PM
Start Macro after user selects a choice from a pick list mathew Excel Discussion (Misc queries) 2 August 17th 06 03:28 PM
Record the time a user selects a macro marcusmccown Excel Programming 0 June 23rd 06 03:31 AM
pause macro until user selects correct range JCIrish Excel Programming 6 March 18th 06 09:26 PM
Cancel Macro is user selects 'cancel' at save menu Mark Excel Programming 1 April 6th 05 05:45 PM


All times are GMT +1. The time now is 12:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"