Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dim As Dictionary. Compile Error: User-defined type not defined

Tags:

rest

excel

vba

Can you please assist with this problem? Whenever I run this macro, it stops at:

Dim authResult As Dictionary

With an error message of: Compile error: User-defined type not defined.

I have not used the dictionary type before and I am trying to re-use this code from a sample macro.

The aim of this script is to use excel to make rest calls to a website so that I can download historic data. I am currently stuck at the login section.

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

Thanks in advance. Cheers, Joe

like image 384
JiggidyJoe Avatar asked Sep 09 '17 06:09

JiggidyJoe


People also ask

How do I fix user defined type not defined in VBA?

Display the References dialog box, and then select the appropriate object library or type library. For example, if you don't check the Data Access Object in the References dialog box, types like Database, Recordset, and TableDef aren't recognized and references to them in code cause this error.

What does compile error user defined type not defined mean?

“not defined”. A possible reason for the error to occur is that you are utilizing the early binding method to declare and define the object, but the required reference has not been added.

How do I fix variable not defined error in VBA?

This error has the following cause and solution: You used an Option Explicit statement to require the explicit declaration of variables, but you used a variable without declaring it. Explicitly declare the variable, or change the spelling of the variable to match that of the intended variable.


1 Answers

Add a reference to Microsoft Scripting Runtime as @YowE3k said:

In the VBA Editor:

Tools -> References

AddRef1

Find Microsoft Scripting Runtime

Check it

Click okay

AddRef2

like image 102
user1274820 Avatar answered Sep 25 '22 02:09

user1274820