VB读取xls数据时提示:不可识别的数据库格式
我将代码COPY到下面了,不知道为什么有这个提示.谢了.Option Explicit
Dim imtdata As Connection
Private Sub Command1_Click()
Dim mypos As Integer
Dim strtemp As String
Dim mystr As String
Dim mypath As String
Dim imtred As Recordset
Dim strfilename As String
dlg.Filter = "xls文件|*.xls"
dlg.DialogTitle = "打开"
dlg.CancelError = True
dlg.ShowOpen
strtemp = dlg.FileName
If strtemp = "" Then Exit Sub
mystr = StrReverse(strtemp)
mypos = InStr(mystr, "\")
mypath = StrReverse(Mid(mystr, mypos))
strfilename = StrReverse(Left(mystr, mypos - 1))
Set imtdata = New Connection
imtdata.ConnectionString = "provider=microsoft.jet.oledb.4.0;persist security info=false;data source= " & mypath & ";extended properties='excel 8.0;HDR=yes';"""
imtdata.CursorLocation = 2
imtdata.Open strtemp
Set imtred = New ADODB.Recordset
imtred.Open "select * from " & strfilename, imtdata, 1, adLockOptimistic
txtfilename.Text = ""
'MsgBox imtred.RecordCount
'Me.DataGrid1.DataSource = imtred
End Sub 97 2000 2003 2007 版本格式的兼容问题 那如何处理呢?我电脑的OFFICE是2003
应该不是格式问题。
把数据源直接指向确定的文件,不要指向一个路径。
补充:VB , 数据库(包含打印,安装,报表)