Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if File Exists or not 2

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi there,

I am new to VBA, so please be patient. :)
I need a Sub Procedure which proofs if a file does exist or not. With following structure:

Sub CheckExistence(file$)

'If file$ = exists Then ....

End Sub

How can I achieve this?

Thanks for your help,
SJ
 
Use the Dir() command.

if Dir(file$) = "" then 'file does not exist

You need to use the whole path name though.

For a function like the one you want, try the following:

Function CheckExistence(filename As String) As Boolean
If Dir(filename) = "" Then
CheckExistence = False
Else
CheckExistence = True
End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top