addHandler problem

  • Thread starter Thread starter GS
  • Start date Start date
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
 
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.
 
Back
Top