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.
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) <> "\" Then
strDir = Directory & "\"
Else
strDir = Directory
End If
strFile = Dir(strDir & "*.XLSX")
TableName = strDir & strFile
While strFile <> ""
I = I + 1
strFile = strDir & strFile
DoCmd.TransferSpreadsheet acImport, , TableName, strFile, True
strFile = Dir()
Wend
importExcelSheets = I
End Function