在Access数据库中插入范围

时间:2016-01-15 19:28:05

标签: excel-vba ms-access vba excel

我想将一个范围A1:A41插入Access表中。它显示错误数据类型不匹配。请建议。

Sub EBD_Uploader()
Dim cn As Object
Dim rs As Object
Dim StrSql As String
Dim strConnection As String
Row = 3

Set cn = CreateObject("ADODB.Connection")
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
    "Data Source=C:\BEO.accdb;"
cn.Open strConnection
Do While Cells(Row, 1) <> ""
    Set Rng = Range(Cells(Row, 1), Cells(Row, 41))
StrSql = "INSERT INTO EDB VALUES ('" & Rng & "') "
Set rs = cn.Execute(StrSql)
    Row = Row + 1
Loop
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub

0 个答案:

没有答案