Warning if other files open

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
 
R

Rick Rothstein

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.
 
G

Gary''s Student

Sub mikef()
n = Workbooks.Count
If n > 1 Then
MsgBox ("WARNING!!!" & Chr(10) & "There are " & n & " workbooks open!!")
End If
End Sub
 
M

MikeF

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.
 
M

MikeF

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
 
Top