Table of contents
Collapse the table of content
Expand the table of content

Invalid use of New keyword

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

The New keyword can only be applied to a creatable object (an instance of aclass orAutomation object). This error has the following causes and solutions:

  • You tried to instantiate something that can have only one instance. For example, you tried to create a new instance of a module by specifying Module1 in a statement like the following:
Dim MyMod As New Module1 
You can't create the new instance, since a module can have only one instance.
  • You tried to instantiate an Automation object, but it was not a creatable object. For example, you tried to create a new instance of a list box by specifying ListBox in a statement like the following:

    ' Valid syntax to create the variable. 
    Dim MyListBox As ListBox     
    Dim MyFormInst As Form 
    ' Invalid syntax to instantiate the object. 
    Set MyFormInst = New Form 
    Set MyListBox = New ListBox 
 **ListBox** and **Form** are class names, not specific object names. You can use them to specify that a[variable]( will be a reference to a certain[object type](, as with the valid  **Dim** statements above. But you can't use them to instantiate the objects themselves in a **Set** statement. You must specify a specific object, rather than the generic class name, in the **Set** statement:
' Valid syntax to create new instance of a form or list box. 
Set MyFormInst = New Form1 
Set MyListBox = New List1 

For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).

© 2018 Microsoft