Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Apr 2002
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error Message illegal use of new keyword (2000)

    I have a program that worked fine in vb. When I ported to vba, received the followign error: "compile error invalid use of new keyword".

    here is the macro tha call a sub

    Option Explicit
    Public m_dctData As Dictionary
    Sub macro1()
    Set m_dctData = New Dictionary
    Call DictSub
    End Sub

    I did select microsoft script runtime as reference

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Error Message illegal use of new keyword (2000)

    Try this adjustment to your code:

    <pre>Option Explicit
    Public m_dctData As Scripting.Dictionary

    Sub macro1()
    Set m_dctData = New Scripting.Dictionary
    Call DictSub
    End Sub
    </pre>

    There is a Dictionary class/object in Word, which unlike the scripting runtime Dictionary, is not a createable object, therefore the error message. So the explicit reference to Scripting.Dictionary is necessary.

    Gary

  3. #3
    Star Lounger
    Join Date
    Apr 2002
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Message illegal use of new keyword (2000)

    Thank you for let me know. I thought it was the same for VB and VBA.

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Error Message illegal use of new keyword (2000)

    The difference with VBA is that you are not just working with the VB language, but with the a host application that has a large object model as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •