可以使用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)表名字后面要加$符号。
设置DatabaseName
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)表名字后面要加$符号。