Dim rsExcel As New ADODB.Recordset
On Error GoTo Err
With dlgCommonDialog
.DialogTitle = "Open"
.CancelError = False
.FileName = ""
'ToDo: set the flags and attributes of the common dialog control
.Filter = "Excel File (*.xls)|*.xls"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
ExcelFile = .FileName
End With
cnExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & ExcelFile & ";Extended Properties='Excel 8.0;HDR=Yes'"
'选取Excel的Sheet1表中的数据
strQuery = "SELECT * FROM [Sheet1$]"
If rsExcel.State = adStateOpen Then rsExcel.Close
rsExcel.Open strQuery, cnExcel, adOpenStatic, adLockOptimistic
MsgBox rsExcel.RecordCount
Err:
Debug.Print Err.Description
错误:外部表不是预期的格式
11 个解决方案
#1
'这样试试
with cnexcel
.cursorlocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
.Open
.CommandTimeout = 300
End With
with cnexcel
.cursorlocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
.Open
.CommandTimeout = 300
End With
#2
一样的错误,两种方法我直接用Office 2000做的Excel文件都可以,但我的导入的Excel文件都是由一个程序输出来的(我估计是Office97格式的)
Dim cnExcel As New ADODB.Connection
Dim rsExcel As New ADODB.Recordset
On Error GoTo Err
With dlgCommonDialog
.DialogTitle = "Open"
.CancelError = False
.FileName = ""
'ToDo: set the flags and attributes of the common dialog control
.Filter = "Excel File (*.xls)|*.xls"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
ExcelFile = .FileName
End With
with cnExcel
.cursorlocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
.Open
.CommandTimeout = 300
End With
'选取Excel的Sheet1表中的数据
strQuery = "SELECT * FROM [Sheet1$]"
If rsExcel.State = adStateOpen Then rsExcel.Close
rsExcel.Open strQuery, cnExcel, adOpenStatic, adLockOptimistic
Debug.Print rsExcel.RecordCount
Err:
Debug.Print Err.Description
[Microsoft][ODBC Excel Driver] 外部表不是预期的格式。
Dim cnExcel As New ADODB.Connection
Dim rsExcel As New ADODB.Recordset
On Error GoTo Err
With dlgCommonDialog
.DialogTitle = "Open"
.CancelError = False
.FileName = ""
'ToDo: set the flags and attributes of the common dialog control
.Filter = "Excel File (*.xls)|*.xls"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
ExcelFile = .FileName
End With
with cnExcel
.cursorlocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
.Open
.CommandTimeout = 300
End With
'选取Excel的Sheet1表中的数据
strQuery = "SELECT * FROM [Sheet1$]"
If rsExcel.State = adStateOpen Then rsExcel.Close
rsExcel.Open strQuery, cnExcel, adOpenStatic, adLockOptimistic
Debug.Print rsExcel.RecordCount
Err:
Debug.Print Err.Description
[Microsoft][ODBC Excel Driver] 外部表不是预期的格式。
#3
也许是Excel版本的问题,改一下连接语句试试:
'Excel 8.0;HDR=Yes' 改为 'Excel 5.0;HDR=Yes'
cnExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & ExcelFile & ";Extended Properties='Excel 8.0;HDR=Yes'"
'Excel 8.0;HDR=Yes' 改为 'Excel 5.0;HDR=Yes'
cnExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & ExcelFile & ";Extended Properties='Excel 8.0;HDR=Yes'"
#4
大概是版本问题,我听说版本高了反儿vb不支持,也不知道什么原因!!
按楼上的说法还不对吗?
按楼上的说法还不对吗?
#5
改为 'Excel 5.0;HDR=Yes'也是一样的错误“外部表不是预期的格式。”
#6
试试这种连接:
cnExcel.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
cnExcel.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
#7
这样连接1:
cnExcel.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
错误如下:
ODBC 驱动程序不支持所需的属性。
这样连接2:
With cnExcel
.CursorLocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
.Open
.CommandTimeout = 300
End With
错误如下:
[Microsoft][ODBC Excel Driver] 外部表不是预期的格式。
cnExcel.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
错误如下:
ODBC 驱动程序不支持所需的属性。
这样连接2:
With cnExcel
.CursorLocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
.Open
.CommandTimeout = 300
End With
错误如下:
[Microsoft][ODBC Excel Driver] 外部表不是预期的格式。
#8
搞不定
UP
UP
#9
你换成excel对象的
.application
.workbook
.worksheet
.range
.cell
用用这种,看行不行吧
.application
.workbook
.worksheet
.range
.cell
用用这种,看行不行吧
#10
谢谢bulletCoderHope(小子),你说的方法行了~!
#11
期待中
#1
'这样试试
with cnexcel
.cursorlocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
.Open
.CommandTimeout = 300
End With
with cnexcel
.cursorlocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
.Open
.CommandTimeout = 300
End With
#2
一样的错误,两种方法我直接用Office 2000做的Excel文件都可以,但我的导入的Excel文件都是由一个程序输出来的(我估计是Office97格式的)
Dim cnExcel As New ADODB.Connection
Dim rsExcel As New ADODB.Recordset
On Error GoTo Err
With dlgCommonDialog
.DialogTitle = "Open"
.CancelError = False
.FileName = ""
'ToDo: set the flags and attributes of the common dialog control
.Filter = "Excel File (*.xls)|*.xls"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
ExcelFile = .FileName
End With
with cnExcel
.cursorlocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
.Open
.CommandTimeout = 300
End With
'选取Excel的Sheet1表中的数据
strQuery = "SELECT * FROM [Sheet1$]"
If rsExcel.State = adStateOpen Then rsExcel.Close
rsExcel.Open strQuery, cnExcel, adOpenStatic, adLockOptimistic
Debug.Print rsExcel.RecordCount
Err:
Debug.Print Err.Description
[Microsoft][ODBC Excel Driver] 外部表不是预期的格式。
Dim cnExcel As New ADODB.Connection
Dim rsExcel As New ADODB.Recordset
On Error GoTo Err
With dlgCommonDialog
.DialogTitle = "Open"
.CancelError = False
.FileName = ""
'ToDo: set the flags and attributes of the common dialog control
.Filter = "Excel File (*.xls)|*.xls"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
ExcelFile = .FileName
End With
with cnExcel
.cursorlocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
.Open
.CommandTimeout = 300
End With
'选取Excel的Sheet1表中的数据
strQuery = "SELECT * FROM [Sheet1$]"
If rsExcel.State = adStateOpen Then rsExcel.Close
rsExcel.Open strQuery, cnExcel, adOpenStatic, adLockOptimistic
Debug.Print rsExcel.RecordCount
Err:
Debug.Print Err.Description
[Microsoft][ODBC Excel Driver] 外部表不是预期的格式。
#3
也许是Excel版本的问题,改一下连接语句试试:
'Excel 8.0;HDR=Yes' 改为 'Excel 5.0;HDR=Yes'
cnExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & ExcelFile & ";Extended Properties='Excel 8.0;HDR=Yes'"
'Excel 8.0;HDR=Yes' 改为 'Excel 5.0;HDR=Yes'
cnExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & ExcelFile & ";Extended Properties='Excel 8.0;HDR=Yes'"
#4
大概是版本问题,我听说版本高了反儿vb不支持,也不知道什么原因!!
按楼上的说法还不对吗?
按楼上的说法还不对吗?
#5
改为 'Excel 5.0;HDR=Yes'也是一样的错误“外部表不是预期的格式。”
#6
试试这种连接:
cnExcel.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
cnExcel.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
#7
这样连接1:
cnExcel.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
错误如下:
ODBC 驱动程序不支持所需的属性。
这样连接2:
With cnExcel
.CursorLocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
.Open
.CommandTimeout = 300
End With
错误如下:
[Microsoft][ODBC Excel Driver] 外部表不是预期的格式。
cnExcel.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
错误如下:
ODBC 驱动程序不支持所需的属性。
这样连接2:
With cnExcel
.CursorLocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=" & excelfile
.Open
.CommandTimeout = 300
End With
错误如下:
[Microsoft][ODBC Excel Driver] 外部表不是预期的格式。
#8
搞不定
UP
UP
#9
你换成excel对象的
.application
.workbook
.worksheet
.range
.cell
用用这种,看行不行吧
.application
.workbook
.worksheet
.range
.cell
用用这种,看行不行吧
#10
谢谢bulletCoderHope(小子),你说的方法行了~!
#11
期待中