|
以下代码是Exce 2003的数据导入word 2003窗体列表框:
Sub UserForm_Activate()
Dim cnn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim SQL$, i&, j&, L&, arr, arr2
Application.ScreenUpdating = False
cnn.Open "Provider=Microsoft.jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=no;imex=1';Data Source=" _
& "C:\WINDOWS\SHELLNEW\PROTTPLO.XLS"
SQL = "SELECT * FROM [Sheet2$A2:A200]"
Set rs = cnn.Execute(SQL)
arr = rs.GetRows
ReDim arr2(0 To UBound(arr, 2), 0 To UBound(arr))
For i = 0 To UBound(arr, 2)
For j = 0 To UBound(arr)
arr2(i, j) = arr(j, i)
Next j
Next i
ComboBox1.ColumnCount = UBound(arr2, 2) + 1
ComboBox1.List = arr2
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
Application.ScreenUpdating = True
ComboBox1.SetFocus '移动光标
End Sub
在word 2003一直能够很好地使用,现我在word 2010中直接将:
cnn.Open "Provider=Microsoft.jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=no;imex=1';Data Source=" _
& "C:\WINDOWS\SHELLNEW\PROTTPLO.xls"
改成:
cnn.Open "provider=Microsoft.ACE.OLEDB.12.0;extended properties='excel 12.0;hdr=no';data source=" _
& "C:\WINDOWS\SHELLNEW\PROTTPLO.xlsx"
运行word 2010宏后,出现如下错误:
请各位老师帮帮忙,我对SQL真的一点都不懂
谢谢
|
|