Using Access 2016:
I have a form:
After I browse for the Excel file. Then I click "Import Excel" button
I get the error: "The file you tried to import was not an Excel Spreadsheet"
I have tried numerous Excel files both xls and xlsx.
Code:
Private Sub btnImportSpreadsheet_Click()
Dim fso As New FileSystemObject
If Nz(Me.txtfilename, "") = "" Then
MsgBox "Please select a file!"
Exit Sub
End If
If fso.FileExists(Nz(Me.txtfilename, "")) Then
ImportExcel.importExcelSpreadsheet Me.txtfilename, "tbl_raw_verizon"
Else
MsgBox "File Not Found"
End If
End Sub
'The above code calls this:
Public Sub importExcelSpreadsheet(filename As String, tablename As String)
On Error GoTo badformat
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, tablename, filename, True
Exit Sub
badformat:
MsgBox "The file you tried to import was not an Excel Spreadsheet"
End Sub
This is the references I have loaded: