Warning if other files open

  • Thread starter Thread starter MikeF
  • Start date Start date
M

MikeF

Need a "warning" MsgBox, saying that another Excel file is open and do I wish
to close it before proceeding, and if yes then close without saving.
In other words, if ActiveWindow.ActivateNext goes anywhere other than the
current file, that warning should pop up.

Thanx,
- Mike
 
Would Workbooks.Count give you what you are looking for? Be careful though,
as it counts the Personal.xls, if it exists, as being open. Perhaps this
line will do what you want...

WBcount = Workbooks.Count + (Len(Workbooks("Personal.xls").Name) > 0)

where if WBcount is greater than 1 then another workbook is open in that
session of Excel (if you have a second session of Excel open, this code will
not see it). Oh, and yes, the + sign in the above code line is correct
because the logical expression evaluates to -1 if true.
 
Sub mikef()
n = Workbooks.Count
If n > 1 Then
MsgBox ("WARNING!!!" & Chr(10) & "There are " & n & " workbooks open!!")
End If
End Sub
 
Thanx.

Rick Rothstein said:
Would Workbooks.Count give you what you are looking for? Be careful though,
as it counts the Personal.xls, if it exists, as being open. Perhaps this
line will do what you want...

WBcount = Workbooks.Count + (Len(Workbooks("Personal.xls").Name) > 0)

where if WBcount is greater than 1 then another workbook is open in that
session of Excel (if you have a second session of Excel open, this code will
not see it). Oh, and yes, the + sign in the above code line is correct
because the logical expression evaluates to -1 if true.
 
Thanx.

Gary''s Student said:
Sub mikef()
n = Workbooks.Count
If n > 1 Then
MsgBox ("WARNING!!!" & Chr(10) & "There are " & n & " workbooks open!!")
End If
End Sub
 

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

Back
Top