I want to be able to import either xls or xlsx files into the same table.
I use the following code and it works 100% for xlsx but gives an error with xls files when importing
the module i use
Error message " external table is not in the expected format" The xls file also do not preview, as xlsx does when clicking on it to import.
Please advise its is driving me to ......
I use the following code and it works 100% for xlsx but gives an error with xls files when importing
Code:
Dim strPath As String With Me strPath = Left(.lblFile.Caption, InStrRev(.lblFile.Caption, "\")) strPath = fsbrowse(strStart:=strPath, _ lngType:=msoFileDialogFilePicker, _ strPattern:="MS Excel,*.XLS; *.XLSX") If strPath > "" Then .lblFile.Caption = strPath Call DoCmd.TransferSpreadsheet(acImport, acSpreadsheetTypeExcel9, "tblDepotInvImport1", strPath, True, "") End If End With
Code:
Public Function fsbrowse(Optional strStart As String = "", _ Optional lngType As MsoFileDialogType = _ msoFileDialogFolderPicker, _ Optional strPattern As String = "MS Excel,*.XLS; *.XLSX") Dim varEntry As Variant Dim fdf As FileDialogFilter 'acSpreadsheetTypeExcel12xml fsbrowse = "" With Application.FileDialog(dialogType:=lngType) 'Set the title to match the type used from the list .Title = "Browse for " Select Case lngType Case msoFileDialogOpen .Title = .Title & "File to open" Case msoFileDialogSaveAs .Title = .Title & "File to SaveAs" Case msoFileDialogFilePicker .Title = .Title & "File" Case msoFileDialogFolderPicker .Title = .Title & "Folder" End Select Call .Filters.clear For Each varEntry In Split(strPattern, "~") Call .Filters.add(Description:=Split(varEntry, ",")(0), _ Extensions:=Split(varEntry, ",")(1)) Next varEntry 'Set some default settings .InitialFileName = strStart .AllowMultiSelect = False .InitialView = msoFileDialogViewDetails 'Only return a value from the FileDialog if not cancelled. If .Show Then fsbrowse = .SelectedItems(1) End With End Function
Please advise its is driving me to ......
Comment