Thread: Existing file ?
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Existing file ?

Hi ceemo,

This works for me -

Sub test()
Dim bGotIt As Boolean
Dim sFile As String
Dim sPath As String

sFile = "Book1.xls"
sPath = "c:\temp\"

'On Error Resume Next
bGotIt = (LCase(sFile) = LCase(Dir(sPath & sFile)))
'On Error GoTo 0

MsgBox bGotIt

End Sub

I though that would need error handling if false, but doesn't seem
necessary.

Regards,
Peter T

"ceemo" wrote in
message ...

Im after some code that will check to see if a file exists in a specific
location.

Ive been given the below two examples but i cant get them to work.


example 1

if Not Dir("C:\DATA\YOURFILE.XLS") then
'the bugger isnot there!
end if


example2

Sub DoesFileExist()
Set MyFile = CreateObject("Scripting.FileSystemObject")
MsgBox MyFile.FileExists("c:\filename.xls")
End Sub


--
ceemo
------------------------------------------------------------------------
ceemo's Profile:

http://www.excelforum.com/member.php...o&userid=10650
View this thread: http://www.excelforum.com/showthread...hreadid=400396