Hello, I have the following code, which opens up a dialogue box and allows the users to select 1 or more files at once. If the user does not select any files (i.e. they hit cancel), I want the macro to end.
The code below works if the user does not select any files, however, if they do I get a "type mismatch" error.
The weird part is that if I completely remove the parts of the code that check to see if any files were selected, the rest of the code works fine (except for an error when the user does not select any files).
Is it related to the "Variant" variable type? By checking to see if it's false am I somehow forcing it to a boolean type, thus causing an error when the variable gets used later on in the code?
Thank you!
The code below works if the user does not select any files, however, if they do I get a "type mismatch" error.
The weird part is that if I completely remove the parts of the code that check to see if any files were selected, the rest of the code works fine (except for an error when the user does not select any files).
Is it related to the "Variant" variable type? By checking to see if it's false am I somehow forcing it to a boolean type, thus causing an error when the variable gets used later on in the code?
Thank you!
Code:
Sub multiSelectV3() Dim myFile As Variant
Dim i As Integer
myFile = Application.GetOpenFilename(MultiSelect:=True)
If myFile = False Then
'Exit Sub
Else
For i = LBound(myFile) To UBound(myFile)
MsgBox Dir(myFile(i))
'Set wb = Workbooks.Open(myFile(i))
Next i
End If
End Sub