ADOX.Table将方括号转换为圆括号

时间:2019-01-18 09:34:26

标签: excel vba ado

如果excel标头的示例名称“毛重为[kg]”的列名中包含[],则ADO将方括号转换为圆括号。

Function GetSheetsNames(WBName As String) As Collection
    'add reference
    Dim objConn As ADODB.Connection ' Microsoft ActiveX Data Objects n.n Library
    Dim objCat As ADOX.Catalog ' Microsoft ADO Ext. 2.8 for DDL and Security.
    Dim tbl As ADOX.Table
    Dim sConnString As String
    Dim sSheet As String
    Dim Col As New Collection

    sConnString = "Provider=Microsoft.ace.OLEDB.12.0;" & _
    "Data Source=" & WBName & ";" & _
    "Extended Properties=Excel 12.0 Xml;"

    Set objConn = New ADODB.Connection
    objConn.Open sConnString
    Set objCat = New ADOX.Catalog
    Set objCat.ActiveConnection = objConn

        For Each tbl In objCat.Tables
            sSheet = tbl.Name
                Set arr2 = tbl.Columns ' here [] changes to ()
        Next tbl
        Set GetSheetsNames = Col
endd:

    objConn.Close
    Set objCat = Nothing
    Set objConn = Nothing
End Function

如何避免这种转换?

0 个答案:

没有答案