Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default SheetActivate/DeActivate events in a common module

Hello Masters,

Is there a way to put sheet activate and deactivate events (for 40
sheets) in a common module, ie. inside a worksheet code module?

Currently I have the codes in the respective sheets. I need all these
codes to be in one sheet.

Is this possible?

Thanks!

-DC

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default SheetActivate/DeActivate events in a common module

Maybe use the Workbook_SheetActivate event ?
It's in the ThisWorkbook module.

NickHK

"Dileep Chandran" wrote in message
ups.com...
Hello Masters,

Is there a way to put sheet activate and deactivate events (for 40
sheets) in a common module, ie. inside a worksheet code module?

Currently I have the codes in the respective sheets. I need all these
codes to be in one sheet.

Is this possible?

Thanks!

-DC



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default SheetActivate/DeActivate events in a common module

Hi Nick,

Thanks for your time. But it doesnt seems to work. Here is the code I
put in ThisWorkbook module:


Private Sub Workbook_SheetActivate(ByVal Sh As Object)

If Sh.CodeName = "Sheet1" Then
MsgBox("Test1")

Else

If Sh.CodeName = "Sheet2" Then
MsgBox("Test2")

End if
End if

End Sub

Any idea what went wrong?

-DC

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default SheetActivate/DeActivate events in a common module

Your workbook event code works fine for me, try this too

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim sCodeName As String

sCodeName = Sh.CodeName

Select Case sCodeName
Case "Sheet1"
MsgBox "Sheet1", , "Case Sheet1"

Case Else
MsgBox sCodeName, , "Case Else"
End Select

End Sub

Bear in mind you might not be able to return codenames of newly insterted
sheets until the wb has been saved or without further intervention.

Regards,
Peter T


"Dileep Chandran" wrote in message
oups.com...
Hi Nick,

Thanks for your time. But it doesnt seems to work. Here is the code I
put in ThisWorkbook module:


Private Sub Workbook_SheetActivate(ByVal Sh As Object)

If Sh.CodeName = "Sheet1" Then
MsgBox("Test1")

Else

If Sh.CodeName = "Sheet2" Then
MsgBox("Test2")

End if
End if

End Sub

Any idea what went wrong?

-DC



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default SheetActivate/DeActivate events in a common module

Thanks Nick & Peter!

I have one more question. Is it possible to put this code in any
worksheet code module other than the ThisWorkbook module?

Thanks for your continued support.

-DC



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default SheetActivate/DeActivate events in a common module

I thought you wanted some centralised way to handle the Activate event ?
This provides it, as it fires for all worksheets.

If you put similar code in a worksheet module, it will only fire for that
specific worksheet, which is what you want to avoid (No ?).

NickHK

"Dileep Chandran" wrote in message
oups.com...
Thanks Nick & Peter!

I have one more question. Is it possible to put this code in any
worksheet code module other than the ThisWorkbook module?

Thanks for your continued support.

-DC



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
XL2003: Is it possible to sink a form's events in a class module ? Michel S. Excel Programming 4 February 20th 07 09:04 AM
Deactivate Events not Firing William Excel Programming 12 July 5th 05 05:12 AM
Common module by multiple workbooks S@S[_2_] Excel Programming 0 November 4th 04 02:39 PM
Common module by multiple workbooks S@S Excel Programming 1 November 4th 04 12:10 PM
What events can be captured in a Class Module? Tom Ogilvy Excel Programming 4 September 8th 03 05:41 AM


All times are GMT +1. The time now is 03:23 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"