Tuesday, February 26, 2013

Find out if a file exists in a directory

'_______________________________________________
'
' Use this function and macro for either Word or Excel to find out
' if a file exists -- they work together
'_______________________________________________
'
Function bFileExists(rsFullPath As String) As Boolean
  bFileExists = CBool(Len(Dir$(rsFullPath)) > 0)
End Function

Sub IfFileExists()
    The_File_Exists = bFileExists("C:\Temp\MyText.txt")
    If The_File_Exists = True Then MsgBox "Yes the file exists"
End Sub

No comments:

Post a Comment

You may comment or show me other VBA tricks, but don't rest assured I'll always reply because I only have 24 hours in a day's hard work, and only a few minutes a week to update this blog... I'll try my best though...