title: Assinging filename to a variable in Excel
body: <p>In excel msoFileDialogFilePicker will return a file name along with its path all I want is the file name. Here is the code that returns both:</p>
  
  <pre><code>Sub GetfileNames()
  
  Dim fd As FileDialog
  
  
  dialogTitle = "Select files for Master Update."
  
  Set fd = Application.FileDialog(msoFileDialogFilePicker)
  
  Dim vrtSelectedItem As Variant
  
  
  With fd
      .InitialFileName = "H:\Desktop\Workforce Project Documents\Update Sandbox\"
      .AllowMultiSelect = True
      .Filters.Clear
      .Title = dialogTitle
      .InitialView = msoFileDialogViewDetails
  
  'This MSG is displayed if the user dose not select a file
          If .Show = False Then
              MsgBox "Files not selected to update. Process Terminated"
              Exit Sub
          End If
  
      'vrtSelectedItem = .SelectedItems(1)
      'vrtSelectedItem = Right(vrtSelectedItem, Len(vrtSelectedItem) - InStrRev(vrtSelectedItem, "\"))
  
  
      For Each vrtSelectedItem In .SelectedItems
  
          MsgBox "Selected file's name is: " &amp; vrtSelectedItem
          'MsgBox "Selected file's name is: " '&amp; vrtSelectedItem = Right(vrtSelectedItem, Len(vrtSelectedItem) - InStrRev(vrtSelectedItem, "\"))
  
      Next
  
  
  'MsgBox "Selected File's name is: " &amp; vrtSelectedItem
  
  End With
  
  End Sub
  </code></pre>
  
  <p>You will notice that I have commented out the line:</p>
  
  <pre><code>'MsgBox "Selected file's name is: " '&amp; vrtSelectedItem = Right(vrtSelectedItem, Len(vrtSelectedItem) - InStrRev(vrtSelectedItem, "\"))
  </code></pre>
  
  <p>which strips out the path because when, I use it it returns the word 'false' also noteworthy is that when I set .AllowMultiSelect to false and only bring in a single value it works fine and I get just the file name. Can anyone see what is wrong? Here is the code for a single variable that works.</p>
  
  <pre><code>Sub GetfileNames()
  
  Dim fd As FileDialog
  
  dialogTitle = "Select files for Master Update."
  
  Set fd = Application.FileDialog(msoFileDialogFilePicker)
  
  Dim vrtSelectedItem As Variant
  
  
  With fd
      .InitialFileName = "H:\jpmDesk\Desktop\Workforce Project Documents\Update Sandbox\"
      .AllowMultiSelect = False
      .Filters.Clear
      .Title = dialogTitle
      .InitialView = msoFileDialogViewDetails
  
  'This MSG is displayed if the user dose not select a file
          If .Show = False Then
              MsgBox "Files not selected to update. Process Terminated"
              Exit Sub
          End If
  
      vrtSelectedItem = .SelectedItems(1)
      vrtSelectedItem = Right(vrtSelectedItem, Len(vrtSelectedItem) - InStrRev(vrtSelectedItem, "\"))
  
  
  MsgBox "Selected File's name is: " &amp; vrtSelectedItem
  
  End With
  
  End Sub
  </code></pre>