使用ADODB.Command加载csv。 SQL子句出错?

时间:2014-08-08 02:36:47

标签: vba csv connection-string adodb

我正在尝试使用ADODB方式将csv加载到VBA中的2D数组:

Function LoadCSVtoArray(strPath As String) As Variant()

    Set cn = CreateObject("ADODB.Connection")
    strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & _
";Extended Properties=""text;HDR=Yes;FMT=Delimited(,)"";"
    cn.Open strcon

    Set cmd = CreateObject("ADODB.Command")
    cmd.ActiveConnection = cn
    cmd.CommandType = adCmdTable
    cmd.CommandText = "mytable#csv"

    Dim rs As Recordset
    Dim rsARR() As Variant

    Set rs = cmd.Execute
    rsARR = WorksheetFunction.Transpose(rs.GetRows)
    Set cn = Nothing

    LoadCSVtoArray = rsARR

End Function

当我到达cmd.Execute行时,我收到以下错误消息:

enter image description here

我在这里缺少哪些明显的东西?

我已经验证了该路径,并且我确信该文件夹中存在mytable.csv

0 个答案:

没有答案