HighTechTalks DotNet Forums  

addHandler problem

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss addHandler problem in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
GS
 
Posts: n/a

Default addHandler problem - 06-18-2007 , 03:11 AM






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





Reply With Quote
  #2  
Old   
SvenC
 
Posts: n/a

Default Re: addHandler problem - 06-18-2007 , 06:56 AM






Hi,

Quote:
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.
--
SvenC



Reply With Quote
  #3  
Old   
GS
 
Posts: n/a

Default Re: addHandler problem - 06-18-2007 , 11:22 AM



wonderful.
Thank you vary much for your helpful and detailed answer.

"SvenC" <SvenC (AT) community (DOT) nospam> wrote

Quote:
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.
--
SvenC




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.