title: Grab File Name Only From Full Path
body: <p>In VBA how can I grab the file name only from the full path that I have below?  When used in my syntax below it imports the full file path (sans the .xlsx) as the table name which is not what I am after.</p>
  
  <pre><code>Public Function importExcelSheets() As Long
  Dim Directory As String, TableName As String, strDir As String, strFile As String, I As Long
  Directory = "C:\Test"
  On Error Resume Next
   I = 0
   If Left(Directory, 1) &lt;&gt; "\" Then
       strDir = Directory &amp; "\"
   Else
       strDir = Directory
   End If
   strFile = Dir(strDir &amp; "*.XLSX")
   TableName = strDir &amp; strFile
   While strFile &lt;&gt; ""
       I = I + 1
       strFile = strDir &amp; strFile
       DoCmd.TransferSpreadsheet acImport, , TableName, strFile, True
       strFile = Dir()
   Wend
   importExcelSheets = I
  End Function
  </code></pre>