locked
Compile error: Method or data member not found RRS feed

  • Question

  • In VBA Excel, why this statement "Set dict = CreateObject (Scripting.Dictionary)" error:

    "Compile error: Method or data member not found". How do I fix it. Please help me!

    Sunday, December 4, 2011 3:38 PM

Answers

  • Make sure you have the correct references set in:

    Tools... > References


    gsnu201111

    When you have your References ticked, its early binding and the code look likes this for example:

    Dim dict As Scripting.Dictionary
    Set dict = New ScriptingDictionary
    

     

    Or with one line:

    Dim dict As New Scripting.Dictionary
    


    In late binding, no references needed, and the code looks like this:

    Dim dict As Object
    Set dict = CreateObject("Scripting.Dictionary")
    


    Advantage of using early binding is you can make use of the intellisense of the Object Library, while with late binding you don't have that available.

    Most of the time I start in early binding, and then convert to late binding when done programming.

     

    Hope this helps,

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    • Marked as answer by cuongdoannhat Thursday, December 22, 2011 5:10 AM
    Sunday, December 4, 2011 4:35 PM

All replies

  • Try this, the Object needs to be in between double quotes:

    Set dict = CreateObject("Scripting.Dictionary")
    


    Hope this helps,

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    • Proposed as answer by danishani Monday, December 5, 2011 8:15 PM
    Sunday, December 4, 2011 4:11 PM
  • Make sure you have the correct references set in:

    Tools... > References


    gsnu201111
    Sunday, December 4, 2011 4:15 PM
  • Also need double quotes:

     

    Set dict = CreateObject("Scripting.Dictionary")


    gsnu201111
    • Proposed as answer by danishani Monday, December 5, 2011 8:16 PM
    Sunday, December 4, 2011 4:19 PM
  • Thank you very much.
    Sunday, December 4, 2011 4:21 PM
  • Thank you, I did that then
    Sunday, December 4, 2011 4:23 PM
  • Make sure you have the correct references set in:

    Tools... > References


    gsnu201111

    When you have your References ticked, its early binding and the code look likes this for example:

    Dim dict As Scripting.Dictionary
    Set dict = New ScriptingDictionary
    

     

    Or with one line:

    Dim dict As New Scripting.Dictionary
    


    In late binding, no references needed, and the code looks like this:

    Dim dict As Object
    Set dict = CreateObject("Scripting.Dictionary")
    


    Advantage of using early binding is you can make use of the intellisense of the Object Library, while with late binding you don't have that available.

    Most of the time I start in early binding, and then convert to late binding when done programming.

     

    Hope this helps,

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    • Marked as answer by cuongdoannhat Thursday, December 22, 2011 5:10 AM
    Sunday, December 4, 2011 4:35 PM
  • Thursday, December 22, 2011 5:11 AM