Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
pk pk is offline
external usenet poster
 
Posts: 5
Default Is a visible workbook open?

Hello, please help on this...

I have an ending subroutine that resets a number of
application elements and is frequently called by any
number of other subroutines.

The only one that causes a problem is the following:

Application.Calculation = xlCalculationAutomatic

I frequently turn calculation off to speed up the code. In
some cases when the code ends, there may be no files open,
in which case the calculation line generates an error.

I really want to keep this code line in the ending
subroutine the way it is structured now. I need your
example code (one line if at all possible) to determine if
any files are open. For example, I tried this, but of
course it doesn't work:

If Not IsEmpty(ActiveWorkBook.Name) Then _
Application.Calculation = xlCalculationAutomatic

I would like something on this order if possible. Ideas?

Your example code most appreciated. Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Is a visible workbook open?

Presumably you are running your macro from a hidden workbook such as Personal.xls. You could detect how many workbooks are open
with:

Workbooks.Count

If only one is open, it is your hidden workbook and you should not run the code..

If Workbooks.Count 1 Then
Application.Calculation = xlCalculationAutomatic
End If

If the situation is more complex, you could simply avoid the error by the following

On Error Resume Next
Application.Calculation = xlCalculationAutomatic
On Error GoTo 0


--

John Green - Excel MVP
Sydney
Australia


"pk" wrote in message ...
Hello, please help on this...

I have an ending subroutine that resets a number of
application elements and is frequently called by any
number of other subroutines.

The only one that causes a problem is the following:

Application.Calculation = xlCalculationAutomatic

I frequently turn calculation off to speed up the code. In
some cases when the code ends, there may be no files open,
in which case the calculation line generates an error.

I really want to keep this code line in the ending
subroutine the way it is structured now. I need your
example code (one line if at all possible) to determine if
any files are open. For example, I tried this, but of
course it doesn't work:

If Not IsEmpty(ActiveWorkBook.Name) Then _
Application.Calculation = xlCalculationAutomatic

I would like something on this order if possible. Ideas?

Your example code most appreciated. Thanks in advance.



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
How to: Open closed workbook/Search data tables/Return data to open workbook Hugh Adams Excel Discussion (Misc queries) 0 August 18th 10 02:04 PM
how do i open a data workbook when i open a timesheet workbook [email protected] uk Excel Discussion (Misc queries) 2 January 4th 09 04:50 PM
Workbook Open but not visible (and not HIDDEN?!?) mcleester Excel Discussion (Misc queries) 0 December 30th 08 03:02 PM
speadsheet wont open but is visible as icon on desktop westwoodview Excel Discussion (Misc queries) 2 June 26th 07 12:51 PM
3 sheets in workbook, but visible only one? slaya_cz Excel Discussion (Misc queries) 3 September 30th 05 01:37 PM


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