Check to see if a file is already open

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

Guest

Hi all

I have a proceedure that opens a certain file the problem is that when the
proceedure is run again it reopens the file where it loses some information,
is there a way to check to see if that file is already open?

Thanks in Advance

Jason
 
Hi Jason

This will check every open workbook by it's name. If your workbook is
already open it will return True in the variable fileopen.

Dim FileOpen As Boolean
Dim wb As Workbook
FileOpen = False
For Each wb In Application.Workbooks
If wb.Name = "NameOfYourWorkbook.xls" Then
FileOpen = True
Exit For
End If
Next 'wb

Regards
Ingolf
 
On Error Resume Next
Set owb = Workbooks("myFile.xls")
On Error GoTo 0
If Not owb Is Nothing Then
MsgBox "Workbook is alraedy open"
Else
Set owb = Workbooks.Open("myFile.xls")
End If


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

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