ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   How to tell the number of current open workbooks... (https://www.excelbanter.com/excel-worksheet-functions/139105-how-tell-number-current-open-workbooks.html)

[email protected]

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!


Duke Carey

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!




All times are GMT +1. The time now is 10:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com