1

好的!直接进代码吧!

代码 :

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")


objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=C:\Users\HV\Desktop\samp.xls;" & _
    "Extended Properties=""Excel 8.0;HDR=Yes;"";" 

objRecordset.Open "Select * FROM [Sheet1$]", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText

objRecordSet.delete 1

错误信息 :

http://s14.postimage.org/fntmbde0x/err.jpg

超大号:

http://s7.postimage.org/4oklf867f/xls.jpg

我期望做的是从记录集中删除第一条记录,只记住记录集不更新到 XLS 中。任何帮助是极大的赞赏 :)

4

1 回答 1

0

您需要一个断开连接的记录集。

  1. 设置Recordset.CursorLocationadUseClient

  2. 打开记录集并获取行

  3. 设置Recordset.ActiveConnectionNothing

现在您可以从记录集中删除记录。

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")


objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=C:\samp.xls;" & _
    "Extended Properties=""Excel 8.0;HDR=Yes;"";"
objRecordSet.CursorLocation = adUseClient
objRecordSet.Open "Select * FROM [Sheet1$]", objConnection, adOpenStatic, adLockOptimistic
Set objRecordSet.ActiveConnection = Nothing
objConnection.Close
objRecordSet.Delete 1
于 2012-05-08T07:26:08.253 回答