Macro code to open a workbook only when closed

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

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