2个回答
推荐于2018-05-12 · 知道合伙人数码行家
关注
展开全部
可以使用DAO,但是Excel数据库是之允许添加、修改、浏览而不允许删除行的:
Sub TestHDRConnectParameter(blnHDRParam As Boolean)
Dim dbs As Database
Dim rst As Recordset
Dim strHDRParam As String
If blnHDRParam = True Then
strHDRParam = "YES"
Else
strHDRParam = "NO"
End If
' Open the Microsoft Jet sample database.
Set dbs = OpenDatabase("C:\JetBook\Samples\Excel\Products97.xls", _
False, False, "Excel 8.0;HDR=" & strHDRParam & ";")
' Create a Recordset object for the Microsoft Excel Products worksheet.
Set rst = dbs.OpenRecordset("Products$")
' Move to the last record and display the RecordCount property value.
With rst
.MoveLast
MsgBox "There are " & .RecordCount & " records in this worksheet."
.Close
End With
dbs.Close
End Sub
注意:
(1)HDR指定是否将首行作为标题行。
(2)表名字后面要加$符号。
Sub TestHDRConnectParameter(blnHDRParam As Boolean)
Dim dbs As Database
Dim rst As Recordset
Dim strHDRParam As String
If blnHDRParam = True Then
strHDRParam = "YES"
Else
strHDRParam = "NO"
End If
' Open the Microsoft Jet sample database.
Set dbs = OpenDatabase("C:\JetBook\Samples\Excel\Products97.xls", _
False, False, "Excel 8.0;HDR=" & strHDRParam & ";")
' Create a Recordset object for the Microsoft Excel Products worksheet.
Set rst = dbs.OpenRecordset("Products$")
' Move to the last record and display the RecordCount property value.
With rst
.MoveLast
MsgBox "There are " & .RecordCount & " records in this worksheet."
.Close
End With
dbs.Close
End Sub
注意:
(1)HDR指定是否将首行作为标题行。
(2)表名字后面要加$符号。
展开全部
完全可以
以下是利用dao3.6来访问的.
Dim db As Database
Dim rs As Recordset
Set db = OpenDatabase(Text2.Text, False, False, "excel 8.0;HDR=YES")
Set rs = db.OpenRecordset(db.TableDefs(0).Name)
利用ado也可以
oConn.Open "Driver={Microsoft Excel Driver (*.xls)};" & _
"DriverId=790;" & _
"Dbq=c:\somepath\mySpreadsheet.xls;" & _
"DefaultDir=c:\somepath;"
以下是利用dao3.6来访问的.
Dim db As Database
Dim rs As Recordset
Set db = OpenDatabase(Text2.Text, False, False, "excel 8.0;HDR=YES")
Set rs = db.OpenRecordset(db.TableDefs(0).Name)
利用ado也可以
oConn.Open "Driver={Microsoft Excel Driver (*.xls)};" & _
"DriverId=790;" & _
"Dbq=c:\somepath\mySpreadsheet.xls;" & _
"DefaultDir=c:\somepath;"
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询