J
JGeniti
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").CodeModule
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
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").CodeModule
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