Hi,
I've got three workbooks that end users will be using for data entry. The VBA code for the three workbooks is identical.
I'm trying to encapsulate the code into an add-in so I only have one copy of the code that I have to debug/maintain.
Furthermore, I've also encapsulated the code in the add-in into a class. The class isn't really a "usual" object modelling some data; rather, it's a utility class processing Worksheet_Change and Worksheet_Activate events. Hopefully this isn't a really bad idea, rather than keeping the code in standard modules in the add-in. Let me know if this is particularly bad design.
The application is called "Midas". Here are some code excerpts:
Midas.xlam:
Standard Module:
Option Explicit
Public Function NewMidasInstance() As CMidas
Set NewMidasInstance = New CMidas
End Function
Class Module:
Option Explicit
'==============================================================================
' CLASS PROPERTIES
'==============================================================================
' Application object
Private WithEvents Wkb As Workbook
...
Private Sub Class_Initialize()
' Get workbook object
Set Wkb = ActiveWorkbook
...
Private Sub Wkb_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.Run Sh.Name & "_Changed", Sh, Target.EntireRow
End Sub
And in the end user workbook:
Public oMidas As Midas.CMidas
Private Sub Workbook_Open()
Set oMidas = Midas.NewMidasInstance()
End Sub
The Wbk_SheetChange event handler is triggering, but it's looking for the code in the end user workbook, instead of the class. Is there a way I can change
Private Sub Wkb_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.Run Sh.Name & "_Changed", Sh, Target.EntireRow
End Sub
to call the private routine "Cases_Changed" (where "Cases" is the sheetname) residing in the class instead of looking for it in the workbook?
Thanks,
Scott
Bookmarks