check if file is open

Adrcon3

New Member
Joined
Aug 29, 2006
Messages
31
i searched the help files on vba and these forums but couldn't find anything. how would i go and check if a file is open or not?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
ohh thanks but i don't get the code lol. is there anyway you can explain it to me?
i get this part
Function CheckFile(strFile As String) As Boolean
Dim Wbk As Workbook
but than everything else doesn't really make sense to me
 
Upvote 0
Hi,

soory for the late answer

This another approach with an example
Code:
Function BookOpen(Bk As String) As Boolean
Dim t As Excel.Workbook
On Error Resume Next
'if the code runs into a error, it skips it and continues
Set t = Application.Workbooks(Bk)
BookOpen = Not t Is Nothing
'   if teh workbook is open, then t will hold the workbook object and _
    therefore will NOT be nothing
On Error GoTo 0
End Function
Sub Test()
Dim isopen As Boolean, bookname As String
book
Name = "Test.xls"
isopen = BookOpen(bookname) ' calling the function
If isopen Then
MsgBox ("is open")
Else
Workbooks.Open Filename:= _
    "C:\Temp\Test.xls"
End If
End Sub

HTH

Cheers,
Roland
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top