ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check to see if a file is already open (https://www.excelbanter.com/excel-programming/365904-check-see-if-file-already-open.html)

Jason Zischke

Check to see if a file is already open
 
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

Ingolf

Check to see if a file is already open
 
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


Bob Phillips

Check to see if a file is already open
 
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)

"Jason Zischke" wrote in message
...
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





All times are GMT +1. The time now is 02:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com