If Dir("C:\path\filename.xls") = "" Then
Msgbox "File Does Not Exist"
End If
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com
"GregW" <gwhi...@nospam.ozemail.com.au> wrote in message
news:RYfI7.333115$bY5.1...@news-server.bigpond.net.au...
Function FileExists(strFileName As String) As Boolean
Dim iDiscard As Long
On Error GoTo FE001
iDiscard = FileLen(strFileName)
FileExists = True
FE000:
On Error GoTo 0
Exit Function
FE001:
FileExists = False
Resume FE000
End Function
Returns True (file does exist)/False (does not exist)
>.
>
This code may help if you want to trap the error.
Sub test()
Dim wb As Workbook
On Error GoTo openErr
Set wb = Workbooks.Open(Filename:="C:\Test.xls")
openErr:
If Err.Number = 1004 Then
MsgBox "File not found"
End If
End Sub
If you just want to ride over it you could use the line
On Error Resume Next
--
HTH
Nick Hodge
Microsoft MVP (Excel)
Southampton, England
nick_...@lineone.net
"GregW" <gwhi...@nospam.ozemail.com.au> wrote in message
news:RYfI7.333115$bY5.1...@news-server.bigpond.net.au...
Regards,
Tom Ogilvy
"GregW" <gwhi...@nospam.ozemail.com.au> wrote in message
news:RYfI7.333115$bY5.1...@news-server.bigpond.net.au...
Function FileExists(strFileName As String) As Boolean
On Error Resume Next
FileExists = FileLen(strFileName) >= 0
End Function
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com
"Media Lint" <webm...@magicdb.net> wrote in message
news:748e01c16c8b$43df5bd0$36ef2ecf@tkmsftngxa12...
FileExists = Not FileLen(strFileName)
(ie True if >=0)
Just a thought.
--
Dana DeLouis Windows Me & Office XP
"Chip Pearson" <ch...@cpearson.com> wrote in message
news:OsjMpyIbBHA.1440@tkmsftngp04...
Function IsFile(S As String) As Boolean
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
IsFile = fs.FileExists(S)
End Function
There is also a way to test for Valid Drives, as Media pointed out.
Function IsDriveValid(S As String) As Boolean
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
IsDriveValid = fs.DriveExists(fs.GetDriveName(S))
End Function
--
Dana DeLouis Windows Me & Office XP
"GregW" <gwhi...@nospam.ozemail.com.au> wrote in message
news:RYfI7.333115$bY5.1...@news-server.bigpond.net.au...