This is less of a problem question, and more of an understanding question.
I stole the code below:
Dim fd as Office.FileDialog
FileDialog.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
.Title = "Please select the file to process."
.Filters.Clear
.Filters.Add "Text files", "*.txt"
.InitialFileName = "C:\"
End With
If fd.Show = -1 Then
sFilename = fd.SelectedItems(1)
Else
MsgBox ("You did not pick a file! Cancelling macro.")
Exit Sub
End If
I do not recall where I got the code from, but it was a while ago. I found this in an old macro and upon looking at it, I do not understand the If
statement.
If fd.Show = -1 Then
I thought Application.FileDialog.Show
was a boolean
expression, and I understand that 0 typically means False, and 1 typically means True. What in the world does -1 mean?
The code works perfectly, and I've tried to research the topic, but everything I find says either "True" or "False". Any insight is much appreciated.