View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Can you capture worksheet double click event from an Add-In????

Sure. Just have your addin instantiate application level events.

See Chip Pearson's page on Application Level events
http://www.cpearson.com/excel/appevent.htm

or look in Excel VBA help at application level events.

--
Regards,
Tom Ogilvy


"JGeniti" wrote in message
oups.com...
Is there a way for me to add code to my add-in file that will capture
the before_doubleclick event of the worksheet that is referencing the
add-in? I currently have thousands of worksheets that are referencing a
single add-in and I need to add a new procedure that gets triggered
when a user double clicks on a specific sheet.

I have tried using the CreateEventProc (example 1) and the InsertLine
(example 2) technique to try to add the event procedure to the
activeworkbook. This has proved to be very unstable. It will work with
some worksheets and crash on others. From what I gathered from my
research, there is an issue with trying to add code to during run-time.

I was just wondering if there is a way that I can just add code to my
add-in that will get triggered when a user double clicks the worksheet.

Any help would be greatly appreciated.
James

Example 1
With ActiveWorkbook.VBProject.VBComponents("Sheet7").Co deModule
StartLine = .CreateEventProc("BeforeDoubleClick",
"Worksheet") + 1
.InsertLines StartLine, "PurchasePartsDblClick Target,
Cancel"
End With

Example 2
Sub AddDblClickEvent()
Dim myVBComp As VBIDE.VBComponent

Set myVBComp = ActiveWorkbook.VBProject.VBComponents("Sheet7")

myVBComp.CodeModule.InsertLines 1, "Private Sub
Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)"
myVBComp.CodeModule.InsertLines 2, "PurchasePartsDblClick Target,
Cancel"
myVBComp.CodeModule.InsertLines 3, "End Sub"
End Sub