Detect if file exists

P

PeterW

Hello.

I am developing a spreadsheet that references other spreadsheets that are
produced on a regular basis.

I would like to check that the file exists before referencing one of its
cells. Can anyone let me know how to check for the existance of a file?

Many thanks.


PeterW
 
B

Bob Phillips

Do you mean if it is open in your instance of Excel? If so, just try
something like

On Error Resume Next
Set oWB = Workbooks(filename)
On Error Goto 0
If Not oWB Is Nothing Then
Msgbox "Workbook is open
End If

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
P

PeterW

Thanks Bob.

I'm afraid no. The spreadsheet will not be open but it may or may not exist
on a server.

It's the test for does it or does it not exist I require.

Regards


PeterW
 
D

Dave Peterson

dim teststr as string
teststr = ""
on error resume next
teststr = dir("yourpath\yourfilenamehere")
on error goto 0

if teststr = "" then
'not found
else
'found
end if


is one way.
 
R

Raymond Cruz

Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(fullFileName) Then
....
EndIf
 

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