|
中文Excel 2000编程2 4学时教程,第21学时使用ADO访问数据,中的示例,总是报错,请帮助修改下。
Sub GoGetProducts()
Dim rsProducts As ADODB.Recordset
Set rsProducts = New ADODB.Recordset
rsProducts.Open
Source = "产品"
ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb"
CursorType = adOpenStatic
LockType = adLockOptimistic
Options = adCmdTable
With Worksheets("Sheet1")
.Range("A1").CurrentRegion.Clear
Application.Intersect(.Range(.Rows(1), .Rows(rsProducts.RecordCount)), .Range(.Columns(1), .Columns(rsProducts.Fields.Count))).Value = MyTranspose(rsProducts.GetRows(rsProducts.RecordCount))
End With
rsProducts.Close
End Sub
Function MyTranspose(ByRef ArrayOriginal As Variant) As Variant
Dim x As Integer
Dim y As Integer
Dim i As Integer
Dim j As Integer
Dim ArrayTranspose() As Variant
x = UBound(ArrayOriginal, 1)
y = UBound(ArrayOriginal, 2)
ReDim ArrayTranspose(y, x)
For i = 0 To x
For j = 0 To y
ArrayTranspose(j, i) = ArrayOriginal(i, j)
Next
Next
MyTranspose = ArrayTranspose
End Function
|
|