vba line continuation with bracket expression [duplicate]

混江龙づ霸主 提交于 2020-01-15 07:12:29

问题


varData = [{"Interbank Placement", "LIBOR/IB/COF"; "cat", "goku"; 4, "cow"; 6, "soccer"; "test", 8; "drinks", "goal"}]

I have a code like this. It is too long and I would like to break it into lines. I tried the code below but it still says missing bracket. How can I do this?

    varData = [{"Interbank Placement", "LIBOR/IB/COF"; _ 
"cat", "goku"; 4, "cow"; 6, "soccer"; "test", 8; "drinks", "goal"}]

回答1:


You can do it by using Evaluate on a string with the array data - but only if the strings are properly quoted. This is a bit of pain, but possible - see below:

Option Explicit

Sub Test()

    Dim strData As String
    Dim varData As Variant

    strData = "{""Interbank Placement"", ""LIBOR/IB/COF"";" & _
        """cat"", ""goku"";" & _
        "4, ""cow"";" & _
        "6, ""soccer"";" & _
        """test"", 8;" & _
        """drinks"", ""goal""}"

    varData = Evaluate(strData)

    MsgBox "varData is array of: " & UBound(varData, 1) & "x" & UBound(varData, 2)

End Sub


来源:https://stackoverflow.com/questions/43175304/vba-line-continuation-with-bracket-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!