' Trap any errors that may occur
On Error Resume Next
' Get a free file handle to avoid using a file handle already in use
f% = FreeFile
' Open the file for reading
Open FileName$ For Input As #f%
' Close it
Close #f%
' If there was an error, Err will be <> 0. In that case, we return False
FileExists% = Not (Err <> 0)
End Function
使用:
if Function FileExists("c:\abc.txt")<>0 then
msgbox "文件存在"
endif