LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
JAC JAC is offline
external usenet poster
 
Posts: 31
Default Devolving code to a DLL

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
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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Run VBA code only worksheet change, but don't trigger worksheet_change event based on what the code does ker_01 Excel Programming 6 October 3rd 08 09:45 PM
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. Corey Excel Programming 3 December 11th 06 05:14 AM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM


All times are GMT +1. The time now is 08:40 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"