title: If File = "False" Application.GetOpenFileName Error 13 Type Mismatch
body: <p>I'm working on a code that uses the Application.GetOpenFileName. Im trying to ensure that that code doesn't break if someone hits cancel when selecting a file. I have a if statement that states if file = "false" then show a msgbox and exit sub. This works fine when no file is selected, however when I run the macro with the files selected then I get a Type Mismatch error. Ive tried a bunch of different runarounds and nothing has worked. Ive looked at other similar questions on here but nothing has worked for me.</p>
  
  <pre><code>Dim nom As String
  Dim wb1, wb2, wb3, wb4, wb5 As Excel.Workbook
  Dim i, j, k, file As Variant
  
  nom = ActiveWorkbook.Name
  If CurDir() &lt;&gt; CurDir("J:") Then
      ChDrive "J:"
      ChDir "J:FEA Material Data"
  End If
  For i = 1 To 5
  Application.ScreenUpdating = False
  MsgBox ("Select Compound" &amp; vbNewLine &amp; vbNewLine &amp; "If Data From Criterion, Select Loading Only" &amp; vbNewLine &amp; vbNewLine &amp; "If Data From Alliance, Select All")
  file = Application.GetOpenFilename( _
              FileFilter:="Text Files (*.csv), *.csv", _
              MultiSelect:=True)
      If file = "False" Then
          MsgBox "No File Selected"
          Exit Sub
      Else
      counter = 1
          While counter &lt;= UBound(file)
              Workbooks.Open file(counter)
              counter = counter + 1
          Wend
      End If 
  more code
  </code></pre>