Check for open workbooks

G

Guest

Hi,

I'm building a database and part of it launches an excel workbook.

Before closing my workbook I'd like to check if there are any other
workbooks open (that the user may be using). If there are no workbooks open
I'd like to completely close Excel, otherwise just close my workbook.

The snag is, I won't know the file names of the other workbooks.

Is there any way you can check for open workbooks without knowing there name?

Thanks
 
R

Ron de Bruin

Hi Steve

If you don't have a hidden personal.xls you can use this

If Application.Workbooks.Count = 1 Then
MsgBox "your close code"
End If

If you have a personal.xls file then you must check for visiblw workbooks
If you need help post back
 
T

Tom Ogilvy

oxlApp.workbooks.count

or


cnt = 0
for each wkbk in oxlApp.workbooks
if wkbk.windows(1).Visible then
cnt = cnt + 1
end if
Next
 
G

Guest

Thanks for the quick reply.

The database is going to be used by approx 30 users so is it possible that
some would have the personal.xls and some wouldn't? If so, how would I
overcome this.

Thanks again.
 
T

Tom Ogilvy

Personal.xls is not opened if you open excel using automation. From you
description, it is hard to tell exactly what you situation is, but I
provided code to check for visible workbooks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top