VBA工具从给定的电子表格中确定SpreadsheetType

我希望使用TransferSpreadsheet命令将电子表格链接或导入到Access 2010中。它需要SpreadsheetType (从AcSpreadSheetType枚举中绘制)的值。 什么是Access VBA工具来确定从给定的电子表格文件名的SpreadsheetType? 也许唯一的手段是检查文件扩展名并做一个查询? 如果您之前已经解决了这个问题,请分享。

考虑到从文件扩展名到特定的Excel格式(见下表)似乎有一个确定的一对多映射,我决定保持它(非常)简单,并且假定只有几种可能的格式是可能的。

我的代码:

 Private Function excel_type(file As String) As Integer Dim ext As String ext = LCase(extension(file)) excel_type = IIf(ext = "xlsx", acSpreadsheetTypeExcel12, _ IIf(ext = "xls", acSpreadsheetTypeExcel9, _ IIf(ext = "xml", acSpreadsheetTypeExcel12Xml, -1))) End Function Public Function extension(file As String) As String extension = Right(file, Len(file) - InStrRev(file, ".")) End Function 

参考表格(随意编辑完整):

 Extn SpreadsheetType Value File format ? acSpreadsheetTypeExcel3 0 Microsoft Excel 3.0 ? acSpreadsheetTypeExcel4 6 Microsoft Excel 4.0 xls acSpreadsheetTypeExcel5 5 Microsoft Excel 5.0 xls acSpreadsheetTypeExcel7 5 Microsoft Excel 95 xls acSpreadsheetTypeExcel8 8 Microsoft Excel 97 xls acSpreadsheetTypeExcel9 8 Microsoft Excel 2000 xlsx acSpreadsheetTypeExcel12 9 Microsoft Excel 2010 xml acSpreadsheetTypeExcel12Xml 10 Microsoft Excel 2010 XML ? acSpreadsheetTypeLotusWJ2 4 ? acSpreadsheetTypeLotusWJ1 ? acSpreadsheetTypeLotusWJ3 ? acSpreadsheetTypeLotusWJ4