Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
cgr cgr is offline
external usenet poster
 
Posts: 4
Default Releasing reference to the Application object before exiting

The Workbook of the Add-In contains the following code:


Private WithEvents MyExcelApp As Excel.Application

Private Sub Workbook_Open()

If MyExcelApp Is Nothing Then

Set MyExcelApp = ThisWorkbook.Application

End If

End Sub


Before exiting Excel, which event in the Add-In's Workbook will allow me to
release the reference (MyExcelApp) to the application?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Releasing reference to the Application object before exiting

Before exiting Excel, which event in the Add-In's Workbook will allow me
to
release the reference (MyExcelApp) to the application?


The Workbook_BeforeClose event would be the place to do this. Note that
if you do this in an unsaved normal workbook rather than an add-in the user
can still stop your workbook from closing if Excel is not prevented from
displaying the save prompt, which fires after the Workbook_BeforeClose
event, potentially leaving the application in a bad state. This situation
shouldn't arise with an add-in, so you'll be OK using it there.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"cgr" wrote in message
...
The Workbook of the Add-In contains the following code:


Private WithEvents MyExcelApp As Excel.Application

Private Sub Workbook_Open()

If MyExcelApp Is Nothing Then

Set MyExcelApp = ThisWorkbook.Application

End If

End Sub


Before exiting Excel, which event in the Add-In's Workbook will allow me
to
release the reference (MyExcelApp) to the application?




  #3   Report Post  
Posted to microsoft.public.excel.programming
cgr cgr is offline
external usenet poster
 
Posts: 4
Default Releasing reference to the Application object before exiting

Rob,

That's what I thought, but for some reason exiting Excel would not raise the
Workbook_BeforeClose event.

Repairing my Office installation seems to have fixed the problem.


Clarence

"Rob Bovey" wrote in message
...
Before exiting Excel, which event in the Add-In's Workbook will allow me
to
release the reference (MyExcelApp) to the application?


The Workbook_BeforeClose event would be the place to do this. Note

that
if you do this in an unsaved normal workbook rather than an add-in the

user
can still stop your workbook from closing if Excel is not prevented from
displaying the save prompt, which fires after the Workbook_BeforeClose
event, potentially leaving the application in a bad state. This situation
shouldn't arise with an add-in, so you'll be OK using it there.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"cgr" wrote in message
...
The Workbook of the Add-In contains the following code:


Private WithEvents MyExcelApp As Excel.Application

Private Sub Workbook_Open()

If MyExcelApp Is Nothing Then

Set MyExcelApp = ThisWorkbook.Application

End If

End Sub


Before exiting Excel, which event in the Add-In's Workbook will allow me
to
release the reference (MyExcelApp) to the application?






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application/Object defined error? Myles Excel Discussion (Misc queries) 0 March 27th 09 07:48 PM
Cannot start the source application for this object oil_driller Excel Discussion (Misc queries) 1 March 3rd 05 03:41 PM
Not releasing workbook reference. [email protected] Excel Programming 0 December 1st 04 03:59 PM
application/object defined error rudekid Excel Programming 1 April 28th 04 04:52 PM
how to get hwnd from application object? Erwin Kalvelagen Excel Programming 2 December 16th 03 07:12 PM


All times are GMT +1. The time now is 02:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"