Hi,
I am a complete VBA beginner so I expect this a very easy question. In the below am trying to check if a file exists. In the below when I check the value of bExists using a Msgbox at the end of the function, the value is true and this is correct. However, if I at the end of the subprocedure as below it returns false. Why is the value of the variable not being passed back to sub?
Thank you in advance for your help.
I am a complete VBA beginner so I expect this a very easy question. In the below am trying to check if a file exists. In the below when I check the value of bExists using a Msgbox at the end of the function, the value is true and this is correct. However, if I at the end of the subprocedure as below it returns false. Why is the value of the variable not being passed back to sub?
Thank you in advance for your help.
VBA Code:
Sub CheckandOpen()
Dim bExists As Boolean
Dim strFullPath As String
Dim strFileName As String
strFullPath = "Desktop/Excel Test Folder/HRIS.xls."
strFileName = Dir(strFullPath)
bExists = CheckExists(strFileName)
MsgBox (bExists)
End Sub
Private Function CheckExists(strFileName) As Boolean
If strFileName = "" Then
bExists = False
Else
bExists = True
End If
End Function