变量声明为字典类型时出现编译错误:用户定义的类型未定义。

21

你能帮忙解决这个问题吗? 每当我运行这个宏,它就停在:

Dim authResult As Dictionary

出现错误信息: 编译错误:未定义用户定义类型。

我以前没有使用过字典类型,并且正在尝试重复使用来自示例宏的此代码。

此脚本的目的是使用Excel向网站发送REST调用,以便我可以下载历史数据。我目前卡在登录部分。

Sub Login()

    Dim userName As String
    Dim password As String
    Dim apiKey As String

    userName = "username"
    password = "password"
    apiKey = "key123"

    'activityTextbox.Text = ""
    'clearData

    Dim authResult As Dictionary
    Set authResult = restClient.authenticateAccount(userName, password, apiKey)
    If Not authResult Is Nothing Then
        'appendActivity "Connected"
        ' Configure Excel to pull streaming updates as often as possible
        Application.RTD.ThrottleInterval = 0
        ' Uncomment for real-time prices - this is very CPU intensive
        ' Buffer interval defaults to 500ms
        'Application.WorksheetFunction.RTD "IG.api.excel.RTD.IGApiRTDServer", "", "bufferInterval", "0"
        ' Set manual refresh to true from very remote locations
        ' Application.WorksheetFunction.RTD "IG.api.excel.RTD.IGApiRTDServer", "", "manualRefresh", "true"
        ' This will require manually calling refresh to update lighstreamer subscriptions, i.e.
        ' Application.WorksheetFunction.RTD "IG.api.excel.RTD.IGApiRTDServer", "", "refresh"
        Dim maxPriceRequestsPerSecond As Double
        maxPriceRequestsPerSecond = 0  ' all available updates
        If restClient.streamingAuthentication(maxPriceRequestsPerSecond) Then
            m_loggedIn = True
            'populateWatchlists
            'populateAccounts
            'manualStreamingRefresh
        'Else
         '   appendActivity "Lightstreamer connection failure"
        End If
    Else
        MsgBox "Authentication failed"
    End If

End Sub

提前致谢。 谢谢, 乔


搜索“vba字典”,你会找到解决方案(或查看相关内容)。 - BitAccesser
4
请在引用中包含“Microsoft Scripting Runtime”。 - YowE3K
1
@YowE3K 我已经包含了它,但我仍然遇到错误。 - Louie Lee
1个回答

40

按照 @YowE3k 的建议,添加对 Microsoft Scripting Runtime 的引用:

在 VBA 编辑器中:

工具 -> 引用

AddRef1

查找 Microsoft Scripting Runtime

选中它

点击确定

AddRef2


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接