通过ADODB.RecordSet打开Excel工作簿

Sub test ()
   Dim dbRng As String
dbRng = Sheet1.Range ("contract") .Address (False, False)
Dim Conn As New ADODB .Connection
Conn .Open "Provider=Microsoft .Jet .OleDb .4.0 ;Extended Properties=Excel 8.0 ;Data Source=" & ThisWorkbook . FullName
Dim Rs As New ADODB .Recordset
Rs .Open "select * from [Sheet1$A1 :C3];", Conn, 3, 3


Do While Not Rs .EOF
    MsgBox ("Contract [" & Rs ("contract #") & " is created by " & Rs ("borrower Name"))
    Rs .MoveNext
Loop
Rs .Close
Set Rs = Nothing
Conn .Close
Set Conn = Nothing


End Sub

你可能感兴趣的:(Excel,VBA,excel,工作,properties,c)