addHandler problem

G

GS

according to help
Dim Obj As New Class1
' Associate an event handler with an event.
AddHandler Obj.Ev_Event, AddressOf EventHandler
is the way to go, so I tried
oBook = oExcel.Workbooks.Add
' Associate an event handler with an event.
AddHandler oBook.WorkbookBeforeClose, AddressOf
xlApp_WorkbookBeforeClose

and I got
Error 4 'WorkbookBeforeClose' is not an event of
'Microsoft.Office.Interop.Excel.Workbook'.

what do I have to do with the handler below to make it work?


Private Sub xlApp_WorkbookBeforeClose(ByVal Wb As Excel.Workbook, _
ByRef Cancel As Boolean)
'Debug.WriteLine("WithEvents: Closing the workbook.")
Wb.Saved = True 'Set the dirty flag to true so there is no prompt to
save
End Sub
 
S

SvenC

Hi,
according to help
Dim Obj As New Class1
' Associate an event handler with an event.
AddHandler Obj.Ev_Event, AddressOf EventHandler
is the way to go, so I tried
oBook = oExcel.Workbooks.Add
' Associate an event handler with an event.
AddHandler oBook.WorkbookBeforeClose, AddressOf
xlApp_WorkbookBeforeClose

and I got
Error 4 'WorkbookBeforeClose' is not an event of
'Microsoft.Office.Interop.Excel.Workbook'.

The event is fired from the Application object. So you would need something
like

AddHandler oExcel.WorkbookBeforeClose, AddressOf xlApp_WorkbookBeforeClose

Assuming that oExcel is of type Excel.Application.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top