Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 16
Default How to tell the number of current open workbooks...

Hello again,

I have a separate function that I need in order to tell how many
workbooks are open besides the one I'm currently in. Basically, I
want to know this so that when the main Macro ends it checks for this
and if there are other workbooks open, it leaves Excel running. If
there aren't any other workbooks open, I want to close the Excel
application completely. This is currently what I had in mind, but it
doesn't work regardless. It gives an error that the "argument is not
optional".

Function WorkbooksOpen() As Boolean

WorkbooksOpen = False
If Len(Application.Workbooks.Open) 1 Then
WorkbooksOpen = True
' Determines that other workbooks are open
' DON'T close Excel
Else
' Determines that other workbooks are NOT open
' DO close Excel
End If

End Function


Any thoughts on this or am I approaching this the wrong way? Is there
a better solution?

Thanks in advance!

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,081
Default How to tell the number of current open workbooks...

Why not check the Workbooks.Count property? You'll have to take your active
book into account, any maybe test for personal.xls (don't want to keep Excel
open if the only other workbook open is Personal.xls).


" wrote:

Hello again,

I have a separate function that I need in order to tell how many
workbooks are open besides the one I'm currently in. Basically, I
want to know this so that when the main Macro ends it checks for this
and if there are other workbooks open, it leaves Excel running. If
there aren't any other workbooks open, I want to close the Excel
application completely. This is currently what I had in mind, but it
doesn't work regardless. It gives an error that the "argument is not
optional".

Function WorkbooksOpen() As Boolean

WorkbooksOpen = False
If Len(Application.Workbooks.Open) 1 Then
WorkbooksOpen = True
' Determines that other workbooks are open
' DON'T close Excel
Else
' Determines that other workbooks are NOT open
' DO close Excel
End If

End Function


Any thoughts on this or am I approaching this the wrong way? Is there
a better solution?

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 do get I my schedule to open at the current date? Maurice Excel Worksheet Functions 1 September 6th 06 05:38 PM
When I open Excel, workbooks open automatically. How can I stop t Rhealbird Excel Discussion (Misc queries) 2 February 23rd 06 10:08 AM
Macro syntax to open file in current explorer folder [email protected] Excel Discussion (Misc queries) 4 January 11th 06 12:07 PM
Excel should open documents in the folder of the current file boxfactory Setting up and Configuration of Excel 0 October 20th 05 03:35 PM
How can I get current cell row number excelneophyte Excel Discussion (Misc queries) 1 October 18th 05 01:08 AM


All times are GMT +1. The time now is 12:34 PM.

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

About Us

"It's about Microsoft Excel"