View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Duke Carey Duke Carey is offline
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!