Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have been trying to devolve most of my VBA code from a spreadsheet
to a DLL, and have had some success. However, I am currently stumped. I am trying without success to put my code for Application events into the DLL, but I can't get the events to fire up as I expected. Can anyone suggest what I might be doing wrong? The following simple code fragment has been put into an ActiveX DLL created in VB6. I have named the project EventLib. I have added the Excel 11.0 and Office 12.0 object libraries to my project references. Currently, the project has one class module, which I have named clsXLEvents, following Chip Pearson's advice. Option Explicit Private WithEvents Appl As Application Private Sub Class_Initialize() MsgBox "Creating Instance", vbOKOnly, "clsXLEvents" Set Appl = Application End Sub Private Sub Appl_NewWorkbook(ByVal Wb As Excel.Workbook) MsgBox "NewWorkbook: " & Wb.Name, vbOKOnly, "DLL clsXLEvents" End Sub Private Sub Appl_WorkbookBeforeClose(ByVal Wb As Excel.Workbook, Cancel As Boolean) MsgBox "WorkbookBeforeClose: " & Wb.Name, vbOKOnly, "DLL clsXLEvents" End Sub Private Sub Appl_WorkbookBeforeSave(ByVal Wb As Excel.Workbook, ByVal SaveAsUI As Boolean, Cancel As Boolean) MsgBox "WorkbookBeforeSave: " & Wb.Name, vbOKOnly, "DLL clsXLEvents" End Sub Private Sub Appl_WorkbookOpen(ByVal Wb As Excel.Workbook) MsgBox "WorkbookOpen: " & Wb.Name, vbOKOnly, "DLL clsXLEvents" End Sub << I have created a simple Excel workbook, called Events.xls, and added the EventLib.dll to my VBA references in the Tools menu. I have placed the following code in ThisWorkbook Option Explicit Private XLAppl As EventLib.clsXLEvents Private Sub Workbook_Open() Stop Set XLAppl = New EventLib.clsXLEvents End Sub << I was hoping to see output from the MsgBox'es when I opened an new workbook, saved a workbook, etc. However, no such events were trapped. Clearly, I am missing something, but I don't know what! Has anyone tried anything similar to this, and had any success? Thank you in anticipation. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
split post code (zip code) out of cell that includes full address | Excel Discussion (Misc queries) | |||
Run VBA code only worksheet change, but don't trigger worksheet_change event based on what the code does | Excel Programming | |||
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. | Excel Programming | |||
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... | Excel Programming | |||
Excel code convert to Access code - Concat & eliminate duplicates | Excel Programming |