Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
Is there a way to trigger a worksheet_change event from code placed in a regular module and not in the sheet itself? Or what is the approach to trigger a worksheet change event when I don't know in advance which sheet will be involved and don't want to insert code at each created sheet? Thanks a lot Avi |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Change Private to Public, eg
Public Sub Worksheet_Change(ByVal Target As Range) and to call it from elsewhere in your project, eg Sheet1.Worksheet_Change Range("A1") Worksheets("Sheet1").Worksheet_Change Range("A1") Unless you are certain Sheet1 will never be deleted, call with Worksheets("Sheet1"). Whilst this should work, I think a better way would be to move the bulk of the event code to a normal module, eg Sub wsChange(ws As Worksheet, Target As Range) ' code End Sub from the worksheet event call it like this Private Sub Worksheet_Change(ByVal Target As Range) wsChange Me, Target End Sub Call it similarly from anywhere else but change 'Me' to [say] ActiveSheet Regards, Peter T "avi" wrote in message ... Hello, Is there a way to trigger a worksheet_change event from code placed in a regular module and not in the sheet itself? Or what is the approach to trigger a worksheet change event when I don't know in advance which sheet will be involved and don't want to insert code at each created sheet? Thanks a lot Avi |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Think I misread your question. As OssieMac suggests use the events exposed
in the ThisWorkbook module, if necessary include some If or Select case to cater for different 'set's of sheets. Regards, Peter T "Peter T" <peter_t@discussions wrote in message ... Change Private to Public, eg Public Sub Worksheet_Change(ByVal Target As Range) and to call it from elsewhere in your project, eg Sheet1.Worksheet_Change Range("A1") Worksheets("Sheet1").Worksheet_Change Range("A1") Unless you are certain Sheet1 will never be deleted, call with Worksheets("Sheet1"). Whilst this should work, I think a better way would be to move the bulk of the event code to a normal module, eg Sub wsChange(ws As Worksheet, Target As Range) ' code End Sub from the worksheet event call it like this Private Sub Worksheet_Change(ByVal Target As Range) wsChange Me, Target End Sub Call it similarly from anywhere else but change 'Me' to [say] ActiveSheet Regards, Peter T "avi" wrote in message ... Hello, Is there a way to trigger a worksheet_change event from code placed in a regular module and not in the sheet itself? Or what is the approach to trigger a worksheet change event when I don't know in advance which sheet will be involved and don't want to insert code at each created sheet? Thanks a lot Avi |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Avi,
The code goes in ThisWorkbook module. The event is the following. Private Sub Workbook_SheetSelectionChange _ (ByVal Sh As Object, ByVal Target As Range) Sh is the worksheet and Target is the range. If you only want the code to run with some worksheets then you can use If/Then/Else or Select Case and test for the worksheet name/s. -- Regards, OssieMac "avi" wrote: Hello, Is there a way to trigger a worksheet_change event from code placed in a regular module and not in the sheet itself? Or what is the approach to trigger a worksheet change event when I don't know in advance which sheet will be involved and don't want to insert code at each created sheet? Thanks a lot Avi . |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() You could create a class module to handle the change event. You can set the events in a sheet change event See chip's webpage 'Events In Excel VBA' (http://www.cpearson.com/EXCEL/Events.aspx) -- joel ------------------------------------------------------------------------ joel's Profile: 229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=170824 Microsoft Office Help |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Worksheet_Change does it fire for a cell changed via foruma? | Excel Programming | |||
event fire | Excel Programming | |||
Can't get Sheet_Change event to fire - please help | Excel Programming | |||
Event doesn't fire | Excel Discussion (Misc queries) | |||
Worksheet_Change event won't fire to execute Macro??? | Excel Programming |