Including "ThisWorkbook" Code in Excel Add-in

I am working on creating a VBA Excel-Add. I need to use Subbook Workbook_SheetChange. Is it possible to include this code as part of the add-in so that all books that use the add-in containing user-defined functions have access to the code that is executed when the sheet is changed?

The file is saved as an .xla add-in. However, "Workbook_SheetChange" will not work from the module and should be located in the code section of the ThisWorkbook file. Therefore, it is not portable with my add-in at this time.

+4
source share
2 answers

Application, WithEvents. CAppEvents.

Private WithEvents mxlApp As Application

Public Property Set App(xlApp As Application)

    Set mxlApp = xlApp

End Property

(Ctrl + F2) mxlApp. SheetChange. , .

Private Sub mxlApp_SheetChange(ByVal Sh As Object, ByVal Target As Range)

End Sub

- , . , , , . , Sh.Parent .

, - .

Public gclsAppEvents As CAppEvents

Sub Auto_Open()

    Set gclsAppEvents = New CAppEvents
    Set gclsAppEvents.App = Application

End Sub

public . Auto_Open , .

+4

.xlam

dim currentworkbook as Workbook
set currentworkbook = activeworkbook

, .

.

thisWorkbook, .xlam thisWorkbook , .

0

Source: https://habr.com/ru/post/1547962/


All Articles