First, you need to go to the "Projects Menu" then click on "References". Look for the reference "Microsoft Scripting Runtime" and put a check mark on it and press the button "OK" to add the reference.
After doing that, we now add our code. Insert this code below anywhere in your program. In my case I choose to put it in a module so that I can access it anytime in every form of my project.
Public Function FileExists(sFullPath As String) As Boolean
Dim oFile As New Scripting.FileSystemObject
FileExists = oFile.FileExists(sFullPath)
End Function
Now you can call on the function like this:
If FileExists("C:\temp\try.txt") Then
Msgbox "File exist."
End If
I hope this snippet has helped you in any way it can. Enjoy!
No comments:
Post a Comment