Hi,
I'm currently taking my first steps into using VBA to manipulate files, and have hit a stumbling block with the Dir function. The code below is a what I'm playing with,
Sub ffile()
ActiveCell = fileExists("fname")
End Sub
Function fileExists(fname) As String
fileExists = Dir(fname)
End Function
...basically, I understand that the Dir function (in this instance) returns the file name of the file from "fname" string if it exists, however, what I'm confused about is if you add ' <>"" ' to the end of the 'fileExists = Dir(fname)' line i.e. 'fileExists = Dir(fname) <>"" ' it returns True or False depending on whether the file exists or not.
I'm struggling to understand why this is the case and was hoping, if it is not too much trouble, if someone could help shed some light as to what this ' <>"" ' additional terms brings/means.
Any help will be hugely appreciated.
Thanks in advance,
Lochnagar
I'm currently taking my first steps into using VBA to manipulate files, and have hit a stumbling block with the Dir function. The code below is a what I'm playing with,
Sub ffile()
ActiveCell = fileExists("fname")
End Sub
Function fileExists(fname) As String
fileExists = Dir(fname)
End Function
...basically, I understand that the Dir function (in this instance) returns the file name of the file from "fname" string if it exists, however, what I'm confused about is if you add ' <>"" ' to the end of the 'fileExists = Dir(fname)' line i.e. 'fileExists = Dir(fname) <>"" ' it returns True or False depending on whether the file exists or not.
I'm struggling to understand why this is the case and was hoping, if it is not too much trouble, if someone could help shed some light as to what this ' <>"" ' additional terms brings/means.
Any help will be hugely appreciated.
Thanks in advance,
Lochnagar