Forward reference to user-defined type

A user-defined type must be defined before it can be referenced. This error has the following causes and solutions:

  • You declared a variable with a user-defined type before the definition of the user-defined type appears. In the following example, the variable OtherVar is declared before its type (OtherType) is known:

      Type MyType 
      OtherVar As OtherType 
      End Type 
    
      Type OtherType 
      WholeVar As Integer 
      RealVar As Double 
      End Type 
    

    Reposition the type definitions so that the forward reference doesn't occur.

  • You nested a user-defined type within itself.

      Type MyType 
      MyVar As Integer 
      OtherVar As MyType 
      End Type 
    

    Remove the self-referencing nested type. This may occur indirectly if you nest a type within another type in which the first is already declared. Check the definition of each nested type to eliminate duplication.

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

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.