Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Event procedure or ............

Hi,
Im trying to get a worksheet change event to work across multiple
templates. Ive tried going through the newsgroup, Chip Pearsons site,
Erlandsen Data site, and a few others and havent really seen anything that
addresses my question. Im trying to use Dave McRitchies code to insert a
row in a sheet via a double click:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Cancel = True 'Eliminate Edit status due to doubleclick - from Dave
McRitchie 09/08/08
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
End Sub

This works fine for the sheet where the code resides in the Personal.xls,
however I would like for it to work across 3 sheets in 6 different workbooks,
all templates. Ive created a class module for the code and activate it in
This Workbook, but it doesnt work. Ive also made sure that enable events
is set to true. How can I make this work? Thanks.
Mark

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Event procedure or ............

"Mark" wrote:

Hi,
Im trying to get a worksheet change event to work across multiple
templates. Ive tried going through the newsgroup, Chip Pearsons site,
Erlandsen Data site, and a few others and havent really seen anything that
addresses my question. Im trying to use Dave McRitchies code to insert a
row in a sheet via a double click:

Cancel = True 'Eliminate Edit status due to doubleclick - from Dave
McRitchie 09/08/08
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
End Sub

This works fine for the sheet where the code resides in the Personal.xls,
however I would like for it to work across 3 sheets in 6 different workbooks,
all templates. Ive created a class module for the code and activate it in
This Workbook, but it doesnt work. Ive also made sure that enable events
is set to true. How can I make this work? Thanks.
Mark


To my knowledge, and I may be wrong, you can't create a generic event
handler to work with mutliple workbooks/sheets. What you can do however is
to plop the following code into a module then call this sub in the event
procedures for each workbook/sheet:

Public Sub DoMyCode(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
End Sub

As an example:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Call DoMyCode(Target, Cancel)
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Event procedure or ............

Hi Mark!

Insert a class module in VBAproject of your Personal.xls with name "clsExcel".

Code for Class Module (clsExcel):

'------------------8<----------------------------
Option Explicit

Public WithEvents XL As Application

Private Sub Class_Terminate()
Set XL = Nothing
End Sub

Private Sub XL_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As
Range, Cancel As Boolean)
If TypeName(Sh) = "Worksheet" Then
Cancel = True 'Eliminate Edit status due to doubleclick - from Dave
'McRitchie 9 / 8 / 8
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
Debug.Print Sh.Name
End If
End Sub
'------------------8<----------------------------

Code for ThisWorkbook code module of PERSONAL.xls:

'------------------8<----------------------------
Option Explicit
Dim objXL As clsExcel

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Me.Saved Then Set objXL = Nothing
End Sub

Private Sub Workbook_Open()
Set objXL = New clsExcel
Set objXL.XL = Excel.Application
End Sub
'------------------8<----------------------------

Ready!

--
John


Ο χρήστης "Magius96" *γγραψε:

"Mark" wrote:

Hi,
Im trying to get a worksheet change event to work across multiple
templates. Ive tried going through the newsgroup, Chip Pearsons site,
Erlandsen Data site, and a few others and havent really seen anything that
addresses my question. Im trying to use Dave McRitchies code to insert a
row in a sheet via a double click:

Cancel = True 'Eliminate Edit status due to doubleclick - from Dave
McRitchie 09/08/08
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
End Sub

This works fine for the sheet where the code resides in the Personal.xls,
however I would like for it to work across 3 sheets in 6 different workbooks,
all templates. Ive created a class module for the code and activate it in
This Workbook, but it doesnt work. Ive also made sure that enable events
is set to true. How can I make this work? Thanks.
Mark


To my knowledge, and I may be wrong, you can't create a generic event
handler to work with mutliple workbooks/sheets. What you can do however is
to plop the following code into a module then call this sub in the event
procedures for each workbook/sheet:

Public Sub DoMyCode(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
End Sub

As an example:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Call DoMyCode(Target, Cancel)
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Event procedure or ............

Thanks, Magius96. I was afraid that I would have to do something like that,
but I was looking for the magic bullit.
Mark

"Magius96" wrote:

"Mark" wrote:

Hi,
Im trying to get a worksheet change event to work across multiple
templates. Ive tried going through the newsgroup, Chip Pearsons site,
Erlandsen Data site, and a few others and havent really seen anything that
addresses my question. Im trying to use Dave McRitchies code to insert a
row in a sheet via a double click:

Cancel = True 'Eliminate Edit status due to doubleclick - from Dave
McRitchie 09/08/08
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
End Sub

This works fine for the sheet where the code resides in the Personal.xls,
however I would like for it to work across 3 sheets in 6 different workbooks,
all templates. Ive created a class module for the code and activate it in
This Workbook, but it doesnt work. Ive also made sure that enable events
is set to true. How can I make this work? Thanks.
Mark


To my knowledge, and I may be wrong, you can't create a generic event
handler to work with mutliple workbooks/sheets. What you can do however is
to plop the following code into a module then call this sub in the event
procedures for each workbook/sheet:

Public Sub DoMyCode(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
End Sub

As an example:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Call DoMyCode(Target, Cancel)
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Event procedure or ............

Thanks, John, but I can't seem to get it to work.
Mark

"John_John" wrote:

Hi Mark!

Insert a class module in VBAproject of your Personal.xls with name "clsExcel".

Code for Class Module (clsExcel):

'------------------8<----------------------------
Option Explicit

Public WithEvents XL As Application

Private Sub Class_Terminate()
Set XL = Nothing
End Sub

Private Sub XL_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As
Range, Cancel As Boolean)
If TypeName(Sh) = "Worksheet" Then
Cancel = True 'Eliminate Edit status due to doubleclick - from Dave
'McRitchie 9 / 8 / 8
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
Debug.Print Sh.Name
End If
End Sub
'------------------8<----------------------------

Code for ThisWorkbook code module of PERSONAL.xls:

'------------------8<----------------------------
Option Explicit
Dim objXL As clsExcel

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Me.Saved Then Set objXL = Nothing
End Sub

Private Sub Workbook_Open()
Set objXL = New clsExcel
Set objXL.XL = Excel.Application
End Sub
'------------------8<----------------------------

Ready!

--
John


Ο χρήστης "Magius96" *γγραψε:

"Mark" wrote:

Hi,
Im trying to get a worksheet change event to work across multiple
templates. Ive tried going through the newsgroup, Chip Pearsons site,
Erlandsen Data site, and a few others and havent really seen anything that
addresses my question. Im trying to use Dave McRitchies code to insert a
row in a sheet via a double click:

Cancel = True 'Eliminate Edit status due to doubleclick - from Dave
McRitchie 09/08/08
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
End Sub

This works fine for the sheet where the code resides in the Personal.xls,
however I would like for it to work across 3 sheets in 6 different workbooks,
all templates. Ive created a class module for the code and activate it in
This Workbook, but it doesnt work. Ive also made sure that enable events
is set to true. How can I make this work? Thanks.
Mark


To my knowledge, and I may be wrong, you can't create a generic event
handler to work with mutliple workbooks/sheets. What you can do however is
to plop the following code into a module then call this sub in the event
procedures for each workbook/sheet:

Public Sub DoMyCode(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
End Sub

As an example:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Call DoMyCode(Target, Cancel)
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Event procedure or ............

Sorry, John - after I closed Excel and reopened it, it works like a charm!
Thanks for your help, I really appreciate it.
Mark

"John_John" wrote:

Hi Mark!

Insert a class module in VBAproject of your Personal.xls with name "clsExcel".

Code for Class Module (clsExcel):

'------------------8<----------------------------
Option Explicit

Public WithEvents XL As Application

Private Sub Class_Terminate()
Set XL = Nothing
End Sub

Private Sub XL_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As
Range, Cancel As Boolean)
If TypeName(Sh) = "Worksheet" Then
Cancel = True 'Eliminate Edit status due to doubleclick - from Dave
'McRitchie 9 / 8 / 8
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
Debug.Print Sh.Name
End If
End Sub
'------------------8<----------------------------

Code for ThisWorkbook code module of PERSONAL.xls:

'------------------8<----------------------------
Option Explicit
Dim objXL As clsExcel

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Me.Saved Then Set objXL = Nothing
End Sub

Private Sub Workbook_Open()
Set objXL = New clsExcel
Set objXL.XL = Excel.Application
End Sub
'------------------8<----------------------------

Ready!

--
John


Ο χρήστης "Magius96" *γγραψε:

"Mark" wrote:

Hi,
Im trying to get a worksheet change event to work across multiple
templates. Ive tried going through the newsgroup, Chip Pearsons site,
Erlandsen Data site, and a few others and havent really seen anything that
addresses my question. Im trying to use Dave McRitchies code to insert a
row in a sheet via a double click:

Cancel = True 'Eliminate Edit status due to doubleclick - from Dave
McRitchie 09/08/08
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
End Sub

This works fine for the sheet where the code resides in the Personal.xls,
however I would like for it to work across 3 sheets in 6 different workbooks,
all templates. Ive created a class module for the code and activate it in
This Workbook, but it doesnt work. Ive also made sure that enable events
is set to true. How can I make this work? Thanks.
Mark


To my knowledge, and I may be wrong, you can't create a generic event
handler to work with mutliple workbooks/sheets. What you can do however is
to plop the following code into a module then call this sub in the event
procedures for each workbook/sheet:

Public Sub DoMyCode(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstant s).ClearContents
On Error GoTo 0
End Sub

As an example:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Call DoMyCode(Target, Cancel)
End Sub

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Event procedure or ............

Restart Excel Mark.
It needs to make the objXL alive.

Try again...

Ο χρήστης "Mark" *γγραψε:

Thanks, John, but I can't seem to get it to work.
Mark


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
event procedure Dave Excel Programming 2 July 29th 08 06:59 AM
Event Procedure doesn't run pat59 Excel Programming 3 July 19th 06 04:00 PM
Event Procedure Paul Johnson[_2_] Excel Programming 1 February 2nd 05 01:29 PM
Event Procedure again Paul Johnson[_2_] Excel Programming 1 February 2nd 05 01:28 PM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM


All times are GMT +1. The time now is 11:14 AM.

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

About Us

"It's about Microsoft Excel"