Opening a Workbook from a Macro

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I'm opening a Workbook (call it Fred) using a macro in a
second workbook (Barney).

Before I use the Workbook.Open command to open Fred I'd
like to check to make sure Fred is not already open.

How can I check check to see if Fred is already open?

Thank you,

Mark
 
Try this with the function

Sub File_Open_test()
If bIsBookOpen("Book11.xls") Then
MsgBox "the File is open!"
Else
MsgBox "the File is not open!"
End If
End Sub

Function bIsBookOpen(ByRef szBookName As String) As Boolean
' Rob Bovey
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function
 
Back
Top