Sub FileImport()
Dim Fldr As String, FldrArr() As Variant
Fldr = "Your File Location here"
FldrArr() = FileCount(Fldr)
If FldrArr(0) = 1 Then
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & Fldr & FldrArr(1) & "", Destination:=Range("$A$5"))
.Name = FldrArr(1)
.Refresh BackgroundQuery:=False
End With
Else
MsgBox FldrArr(1)
End If
End Sub
Private Function FileCount(Folder As String) As Variant
Dim objFSO As Object
Dim objFile As Object
Dim objFolder As Object
Dim Name As String
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object associated with the directory
Set objFolder = objFSO.GetFolder(Folder)
Select Case objFolder.Files.Count
Case 0
FileCount = (Array(objFolder.Files.Count, "No Files were Found in " & Folder))
Case 1
For Each objFile In objFolder.Files
Name = objFile.Name
Next
FileCount = (Array(objFolder.Files.Count, Name))
Case Else
FileCount = (Array(objFolder.Files.Count, "There is more than one file in " & Folder))
End Select
'Clean up!
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Function