File open?

J

jille

Hi,

I'm writing a macro that tests to see if an Excel file is currently open.
I've tried the following with no luck:

if Excel.application.workbooks(File).open = true then
....
end if

Any ideas?

Thanks,
Jille
 
P

Perry

Utilize below/bottom examplified function as in below immediate window
quest:

? fileisopen("c:\data\ta\ta\ta\myfile.xls")
False

'= VBA function outlay
Function FileIsOpen(ByVal FileName As String) As Boolean
Dim i As Integer
i = FreeFile
On Error GoTo ErrOpenFile
Open FileName For Binary Access Read Lock Read As #i
Close #i
FileIsOpen = True
ExitHere:
Exit Function
ErrOpenFile:
Resume ExitHere
End Function

Krgrds,
Perry
 

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

Top