Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Resetting Excel commandbars on close event

I am automating certain aspects of Excel (and Word) using c#. I am able
to hide various commandbars and controls from the user. My problem is
that I have difficulty resetting the bars when Excel closes. I have
read some articles and threads relating to the Excel close event (or
lack of it) at the application level, but have not found any answers to
this problem.

I am using the workbook_close event to execute some code already, but I
find that when I try to reset the command bars directly from this event
handler Excel just freezes. The only way I have found so far to reset
the bars without any errors is to start a new process from this event
handler that will use a new Excel ApplicationClass and reset the bars,
before closing (without ever being visible). The problem with this is
that I have to insert a delay of around 20 seconds before starting this
new process otherwise Excel bombs out with a memeory referencing
error.

I find it hard to believe that I can remove bars and controls from my
original application, but I cannot reset them from this event handler.

Does anyone know why Excel might be freezing in this way, or how I can
reset the controls without having to use a separate process and a
delay?


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Resetting Excel commandbars on close event

Hi Alanperu,

I am using the workbook_close event to execute some code already, but I
find that when I try to reset the command bars directly from this event
handler Excel just freezes.


Try moving the code that handles the commandbars to a sub in a normal
module. Call that sub from the Workbook_BeforeClose event.

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Resetting Excel commandbars on close event

Unfortunately this was something that I have already tried. It seems
that Excel always hangs if the reset code is part of or called from the
event handler. This was why I tried it using a different process.

Thanks anyway,

Any other ideas?


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Resetting Excel commandbars on close event

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Resetting Excel commandbars on close event

Hi Alanperu,

Unfortunately this was something that I have already tried. It seems
that Excel always hangs if the reset code is part of or called from the
event handler.


Try it like this:

In a normal module:

Option Explicit

Public bClose As Boolean

Sub NowClose()
bClose = True
MsgBox "Place a call to the menuhandler here. "
ThisWorkbook.Close
End Sub

In the Thisworkbook module:

Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If bClose Then Exit Sub
Cancel = True
Application.OnTime Now, "Nowclose"
End Sub


Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com

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
before close event with condition mohavv Excel Discussion (Misc queries) 4 November 21st 07 03:14 AM
Trapping Excel Close Event Bob J.[_2_] Excel Programming 3 December 6th 03 08:57 PM
Trapping Excel Close event Bob J[_2_] Excel Programming 3 December 5th 03 11:56 PM
Excel main window close event Avneesh Saxena Excel Programming 2 November 21st 03 07:42 PM
After Close Event? Don Wiss Excel Programming 2 November 19th 03 12:30 AM


All times are GMT +1. The time now is 09: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"