excel In =RTD(ProgID,服务器,字符串1,[字符串2],...),为字符串2、字符串3等传递数组

eh57zj3b  于 2023-01-27  发布在  其他
关注(0)|答案(1)|浏览(139)

有没有办法把myStringArray传递给RTD函数

Data = "A,B,C"
Dim myStringArray() As String     `
myStringArray = Split(Data, ",")`

Application.WorksheetFunction.RTD("rtd.server.1", "", "" + URL+ "", "User", "Query", myStringArray)

期望RTD服务器接收“URL”、“用户”、“查询”、“A”、“B”、“C”作为参数。我尝试了上面的方法,但没有成功。

w7t8yxp5

w7t8yxp51#

由于WorksheetFunction.RTD()方法(https://learn.microsoft.com/en-us/office/vba/api/excel.worksheetfunction.rtd)* 签名 *(即:它接受的参数数量和类型),您可以使用“预处理器”,如下所示:

Sub PreProcessingForRTD(progID As Variant, server As Variant, topic1 As Variant, ParamArray otherTopics() As Variant)

    Dim topics(1 To 28) As Variant
    
    topics(1) = topic1
    
    Dim iTopic As Long
        iTopic = 1
        Dim arg As Variant
        For Each arg In otherTopics
            Select Case True
                Case IsArray(arg)
                    Dim argArg As Variant
                        For Each argArg In arg
                            iTopic = iTopic + 1
                            topics(iTopic) = argArg
                        Next
                Case Else
                    iTopic = iTopic + 1
                    topics(iTopic) = arg
                    
            End Select
        Next

    'change 'Debug.Print' to whatever real usage you are making of 'Application.WorksheetFunction.RTD()'
    Debug.Print Application.WorksheetFunction.RTD(progID, server, topics(1), _
                                                  topics(2), topics(3), topics(4), topics(5), topics(6), topics(7), topics(8), topics(9), topics(10), topics(11), topics(12), topics(13), topics(14), topics(15), topics(16), topics(17), topics(18), topics(19), topics(20), topics(21), topics(22), topics(23), topics(24), topics(25), topics(26), topics(27), topics(28))

    
End Sub

您将在“主”子系统中使用,如下所示:

Dim DATA As String
    DATA = "A,B,C"

Dim myStringArray() As String
    myStringArray = Split(DATA, ",")

Dim url As String
    url = "myURL"
    
PreProcessingForRTD "rtd.server.1", "", "" + url + "", "User", "Query", myStringArray

相关问题