Macro code to open a workbook only when closed

Macro code to open a workbook only when closed

Post by SmVmZ » Sat, 18 Feb 2006 05:00:29


How can I check in a macro subroutine if the status of another file is open
or close. I would like to open another file only when it is not open.
Otherwise, Workbooks.Open Filename:="myfile.xls" simply returns an error
when the file is already open while the macro is running. Thanks a lot in
advance.
 
 
 

Macro code to open a workbook only when closed

Post by S2V2aW4gQ » Sat, 18 Feb 2006 05:23:29

You can use the following custom function to determine if the workbook is open.
======================================================
Function WBOpen(WorkBookName As String) As Boolean

On Error GoTo WorkBookNotOpen

If Len(Application.Workbooks(WorkBookName).Name) > 0 Then
WBOpen = True
Exit Function
End If

WorkBookNotOpen:

End Function
======================================================
--
Kevin Backmann