An Explanation of Trappable Errors in Visual Basic for Apps

Last reviewed: February 2, 1998
Article ID: Q142138
The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel for Windows 97, version 8.0
  • Microsoft Excel 98 Macintosh Edition
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Project for Windows, versions 4.0, 4.1
  • Microsoft Project for Macintosh, version 4.0

SUMMARY

This article a contains detailed descriptions of the trappable error messages that can be used with the Err function in Visual Basic for Applications.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/supportnet/refguide/

Return without GoSub (Error 3)

A Return statement does not have a corresponding GoSub statement. Unlike For...Next, While...Wend, and Sub...End Sub, which are matched at compile time, GoSub and Return are matched at run time.

Invalid procedure call (Error 5)

An argument probably exceeds the range of permitted values. For example, the Sin function can only accept values within a certain range. Positive arguments less than 2147483648 are accepted, while 2147483648 generates this error.

This error may also occur if an attempt is made to call a procedure that is not valid on the current platform. For example, some procedures may only be valid for the Macintosh, or for Microsoft Windows, and so forth.

Overflow (Error 6)

Possible causes for this error are:

  • The result of an assignment, calculation, or data type conversion is too large to be represented within the range allowed for that type of variable.

        -or-
    
  • An assignment to a property exceeds the maximum value the property can accept.

Out of memory (Error 7)

More memory was required than is available or a 64K segment boundary was encountered. To prevent this error, try the following:

  • Close any unnecessary applications, documents, or source files that are in memory.
  • If you have extremely large modules or procedures, consider breaking them into smaller ones. This procedure doesn't save memory, but it can prevent hitting 64K segment boundaries.
  • If you are running Microsoft Windows in standard mode on an 80386 or 80486 computer, try running it in enhanced mode.
  • If you are running Microsoft Windows in enhanced mode, free up some disk space, or at least ensure that some space is available.
  • Eliminate terminate-and-stay-resident (tsr) programs.
  • Eliminate unnecessary device drivers.
  • Reduce the number of global variables.

Subscript out of range (Error 9)

You have referenced a nonexistent array element or collection member. The subscript may be larger or smaller than the range of possible subscripts, or the array may not have dimensions assigned at this point in the application.

Duplicate definition (Error 10)

This error usually occurs only when generated from code, as in the following example:

   Error 10

However the error may also occur if you try to use ReDim to change the number of elements of a fixed-size array. For example, in the following code, the fixed array FixedArr is received by SomeArr in the procedure NextOne, then an attempt is made to resize SomeArr:

   Sub FirstOne

   Static FixedArr(25) As Integer   ' Create a fixed-size array
      NextOne FixedArr()            ' and pass it to another sub.

   End Sub

   Sub NextOne(SomeArr() As Integer)

   ReDim SomeArr(35)   ' Duplicate definition occurs here.
   . . .
   End Sub

Division by zero (Error 11)

The value of an expression being used as a divisor is zero. Check the spelling of variables in the expression. A misspelled variable name can implicitly create a numeric variable that is initialized to zero. Check previous operations on variables in the expression, especially those passed into the procedure as arguments from other procedures.

Type mismatch (Error 13)

Possible causes for this error are:

  • The variable or property is not of the correct type. For example, a variable that requires an integer value can't accept a string value.
  • An object has been passed to a procedure that is expecting a single property or value.
  • A module or project name was used where an expression was expected, for example:

          Debug.Print MyModule
    
  • You attempted to mix traditional Basic error handling with variant values having the Error subtype (10, vbError); for example:
  • Error CVErr(n)

    A CVErr value can't be converted to Date or numeric types (Integer, Long, and so on); for example:

          MyVar = CInt(CVErr(9))
    

    At run time, this error typically indicates that a Variant used in an expression has an incorrect subtype, or that a Variant containing an array appeared in a Print statement.

Out of string space (Error 14)

Your system may have run out of memory, which has prevented a string from being allocated. Similarly, expressions requiring that temporary strings be created for evaluation may be causing this error. For example, the following code will cause an Out of string space error:

     MyString = "Hello"
       For Count = 1 To 100
     MyString = MyString & MyString
     Next Count

Visual Basic lets you allocate a string with a maximum length of 65,535 characters. However, in executing statements at run time, the host application needs to use some string space for overhead. The amount of overhead varies among hosts, but should not exceed 50 bytes. If you need to allocate a string of the maximum length your host can support, reduce the string size by 50 bytes, then increase the length incrementally until this error is generated again. The value immediately preceding the error represents the host's maximum string length.

   Dim MyString As String * 65485
                      ' Start with (65535-50).
                      ' On successive runs, increment
                      ' length until "Out of string
                      ' space" error occurs.
   Sub MySub
        MyString = "string" ' Error occurs here when the
   End Sub                  ' maximum length is exceeded.

String formula too complex (Error 16)

A string expression is too complicated. Strings not assigned to variables (such as those returned by functions) are assigned to temporary locations during string expression evaluation. Having a large number of these strings can cause this error. Try assigning these strings to variables and use the variables in the expression instead.

Can't perform requested operation (Error 17)

The requested operation can't be performed because it would invalidate the current state of the project. For example, the error occurs if you use the References dialog box (on the Tools menu, click Rererences) to add a reference to a new project or object library while a program is in break mode.

User interrupt occurred (Error 18)

A CTRL+BREAK or other interrupt key has been pressed by the user.

Resume without error (Error 20)

A Resume statement has been encountered, but it is either outside the error handler code, or it was encountered while there was no error-handling routine active.

Out of stack space (Error 28)

Possible causes for this error are:

  • Too many active Function or Sub calls. Check that general recursive procedures are not nested too deeply and that they terminate properly.
  • Local variables require more local variable space than is available. Try declaring some variables at the module level instead. You can also declare all variables in the procedure static by preceding the Property, Sub, or Function keyword with Static. Or, you can use the Static statement to declare individual static variables within procedures.
  • Fixed-length strings use more stack space than variable-length strings. Try redefining some of your fixed-length strings as variable-length strings.
  • Too many nested DoEvents statements.

Use the Calls dialog box to view which procedures are active (on the stack). To display the Calls dialog box, select the button to the right of the Procedures box in the Debug window.

Sub or function not defined (Error 35)

A Sub, Function, or Property procedure is called but is not defined.

Possible causes for this error are:

  • You have misspelled the name of your procedure.
  • The specified procedure is not visible to the calling procedure. Procedures declared Private in one module can't be called from procedures outside the module. If Option Private Module is in effect, procedures in the module are not available to other projects. Choose Find from the Edit menu to locate the procedure.
  • You have declared a dynamic-link library (DLL) routine, but the routine is not in the specified library.

Error in loading DLL (Error 48)

The specified dynamic-link library (DLL) can't be loaded. This is usually because the file specified with the Lib clause in the Declare statement is not a valid DLL.

Possible causes for this error are:

  • The file is not DLL-executable.
  • The file is not a Microsoft Windows DLL.
  • The file is an old Microsoft Windows DLL that is incompatible with Microsoft Windows protect mode.
  • The DLL references another DLL that is not present.
  • The DLL or one of the referenced DLLs is not in a directory specified by your path.

Bad DLL calling convention (Error 49)

Your program is calling a routine in a dynamic-link library (DLL) that either is being passed the wrong type or number of arguments or does not use the Pascal calling convention. Make sure that the arguments passed to the DLL routine exactly match the arguments expected by the routine. If the DLL routine expects arguments by value, then make sure ByVal is specified for those arguments in the declaration for the routine.

Internal error (Error 51)

An internal malfunction has occurred in Visual Basic. Unless this call was generated by the Error statement, contact Microsoft Product Support Services to report the conditions under which the message appeared.

Bad file name or number (Error 52)

A statement refers to a file with a file number or file name that is:

  • An invalid name or number
  • Not specified in the Open statement
  • Specified in an Open statement, but has since been closed
  • Out of the range of file numbers (1-511)

In Microsoft Windows, use the following conventions for naming files and directories:
  • The name of a file or directory can have two parts: a name and an optional extension. The two parts are separated by a period, for example, Myfile.new.
  • The name can contain up to eight characters, and the extension can contain up to three characters.
  • The name must start with either a letter or number. It can contain any uppercase or lowercase (file names are not case-sensitive) characters except the following:

       Character     Description
       ----------------------------------
    
        .           Period
        "           Quotation mark
        '           Single quotation mark (apostrophe)
        +           Plus sign
        /           Slash
        \           Backslash
        [ ]         Brackets
        :           Colon
        ;           Semicolon
        |           Vertical bar (pipe)
        =           Equal sign
        ,           Comma
    
    
  • The name should not contain any spaces. The following names are reserved and can't be used for files or directories: CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, PRN, and NUL. For instance, if you try to name a file PRN in an Open statement, the default printer will simply become the destination for Print #, and Write # statements directed to the file number specified in the Open statement.
  • The following are examples of valid Microsoft Windows file names:

          LETTER.DOC
          MEMO.TXT
          BUDGET.92
          12345678.901
          2NDTRY.RPT
    
  • On the Macintosh, a file can have any character except the colon (:), and may contain spaces. Null characters [Chr(0)] are not allowed in any file names.

File not found (Error 53)

Possible causes for this error at run time are:

  • A statement (for example, Kill, Name, or Open) refers to a file that does not exist.
  • An attempt has been made to call a procedure in a dynamic-link library (DLL), but the library file name specified in the Lib clause of the Declare statement can't be found.

In the development environment, this error occurs if you attempt to open a project or load a text file that does not exist.

Bad file mode (Error 54)

Possible causes for this error are:

  • A Put or Get statement is specifying a sequential file. Note that Put and Get can only refer to files opened for Random access.
  • A Print # statement specifies a file opened for an access mode other than Output or Append.
  • An Input # statement specifies a file opened for an access mode other than Input.
  • Any attempt to write to a read-only file.

File already open (Error 55)

Possible causes for this error are:

  • A sequential-output mode Open statement was executed for a file that is already open.
  • A statement (for example Kill, SetAttr, or Name) refers to an open file.

Device I/O error (Error 57)

An input or output error occurred while your program was using a device such as a printer or disk drive.

File already exists (Error 58)

At run time, this error occurs when the new file name (for example, one specified in a Name statement) is identical to a file name that already exists. It also occurs when you use Save As to save a currently loaded project if the project name already exists.

Bad record length (Error 59)

The length of a record variable for a Get or Put statement does not match the length specified in the corresponding Open statement. Because a two- byte descriptor is always added to a variable-length string Put to a random access file, the variable-length string must be at least two characters shorter than the record length specified in the Len clause of the Open statement.

Variant data types also require a two-byte descriptor. Variants containing variable-length strings require a four-byte descriptor. Therefore, for variable-length strings in a Variant, the string must be at least 4 bytes shorter than the record length specified in the Len clause.

Disk full (Error 61)

Possible causes for this error are:

  • There is not enough room on the disk for the completion of a Print #, Write #, or Close operation.
  • There is not enough room on the disk to create required files.

To work around this situation, move some files to another disk, or delete some files.

Input past end of line (Error 62)

An Input # or Line Input # statement is reading from a file in which all data has already been read or from an empty file. To avoid this error, use the EOF function (immediately before the Input # statement) to detect the end of file.

Bad record number (Error 63)

The record number in a Put or Get statement is less than or equal to zero.

Too many files (Error 67)

Possible causes for this error are:

  • There is a limit to the number of disk files that can be open at one time. For Microsoft Windows, this limit is a function of the Files= setting in your CONFIG.SYS file. Increase that number and reboot.
  • The operating system has a limit to the number of files in the root directory (usually 512). If your program is opening, closing, or saving files in the root directory, change your program so that it uses a subdirectory.
  • On the Macintosh, the standard limit is 40 files. This limit can be changed using a utility to modify the MaxFiles parameter of the boot block.

Device unavailable (Error 68)

The device you are trying to access is either not online or does not exist.

Permission denied (Error 70)

An attempt was made to write to a write-protected disk or to access a locked file. For example, this error will occur if an Open For Output statement is performed on a write-protected file.

Disk not ready (Error 71)

There is either no disk in the drive specified or the drive door is open. Insert a disk in the drive, close the door, and retry the operation.

Can't rename with different drive (Error 74)

You can't use the Name statement to rename a file with a new drive designation. Use FileCopy to write the file to another drive, and delete the old file with a Kill statement.

Path/File access error (Error 75)

During a file- or disk-access operation (for example, Open, MkDir, ChDir, or RmDir), the operating system could not make a connection between the path and the file name.

Make sure the file specification is formatted correctly. A file name can contain a fully-qualified or relative path. A fully-qualified path starts with the drive name (if the path is on another drive) and lists the explicit path from the root to the file. Any path that is not fully qualified is relative to the current drive and directory. This error can also occur while attempting to save a file that would replace an existing read-only file.

Path not found (Error 76)

During a file- or disk-access operation (for example, Open, MkDir, ChDir, or RmDir), the operating system was unable to find the specified path. The error also occurs in the debugging environment if you attempt to open a project or insert a text file with an invalid path. Make sure the path is typed correctly.

Object variable not set (Error 91)

You are attempting to use an object variable that is not yet referencing a valid object, or one that has been set to Nothing. Specify or respecify a reference for the object variable. For example, if the Set statement were omitted in the following code, an error would be generated:

   Dim MyObject As Object     ' Creates object variable.
   Set MyObject = Sheets(1)   ' Creates valid object reference.
   MyCount = MyObject.Count   ' Assigns Count value to MyCount.

For Loop not initialized (Error 92)

You've jumped into the middle of a For...Next loop. Placing labels inside a For...Next loop is not recommended.

Invalid pattern string (Error 93)

The pattern string specified in the Like operation of a search is invalid. A common example of an invalid character list expression is [a-b , where the right bracket is missing.

Invalid use of Null (Error 94)

You are trying to obtain the value of a variant variable or an expression that is Null. Null is a variant subtype used to indicate that a data item contains no valid data. For example:

   MyVar = Null
   For Count = 1 To MyVar
   . . .
   Next Count

Can't load module; invalid format (Error 323)

The module you attempted to load is not a text module. Some versions of Visual Basic permit you to save code in both binary and text formats. If possible, reload the file in the application in which it was last saved and save it as text. This error code applies to Microsoft Excel for Windows 95, version 7.0 only.

Property or method not found (Error 423)

Object.method or object.property is referred to, but method or property is not defined, or you may have misspelled the name of the object. To see what properties and methods are defined for an object, choose the Object Browser from the View menu. Select the appropriate library and object to display available properties and methods.

Object required (Error 424)

You have referred to an object property or method, but have not provided a valid object qualifier.

Class doesn't support OLE Automation (Error 430)

The object specified in the GetObject or CreateObject function call was found, but has not exposed a programmability interface. Therefore you can't write code to control this object's behavior. Check the documentation of the application that created the object for limitations on the use of OLE Automation with this class of object.

Object doesn't support this property or method (Error 438)

This method or property does not exist for this OLE automation object. See the object's documentation for more information on the object and to check the spellings of properties and methods.

OLE Automation error (Error 440)

An error occurred while executing a method or accessing a property of an object variable. The error was reported by the application that created the object.

Object doesn't support this action (Error 445)

This method or property is not supported by this object. See the object's documentation for more information on the object and to check the spellings of properties and methods.

Object doesn't support named arguments (Error 446)

Arguments can only be specified by position when performing methods on this object. See the object's documentation for more information on argument positions and types.

Object doesn't support current locale settings (Error 447)

The object you are attempting to access does not support the locale setting for the current project. For example, if your current project has the locale setting Canadian French, the object you are trying to access must support that locale setting. Check which locale settings the object supports.

Also note that the object may rely on national language support in a dynaminc-link library (DLL), for example OLE2NLS.DLL. If so, you may need a more recent version that supports the current project locale.

Named argument not found (Error 448)

You specified a named argument, but the procedure was not defined to accept an argument by that name. Check the spelling of the argument name.

Argument not optional (Error 449)

The number and types of arguments must match those expected. For instance, the Left function requires two arguments, the first representing the character string being operated on, and the second representing the number of characters to return from the left side of the string. Because neither argument is optional, both must be supplied.

An argument can only be omitted from a call to a user-defined procedure if it was declared Optional in the procedure declaration.

Wrong number of arguments (Error 450)

The number of arguments in the call to the procedure was not the same as the number of arguments expected by the procedure. Check the argument list in the call against the procedure declaration.

Object not a collection (Error 451)

You have specified an operation or property that is exclusive to collections, but the object is not a collection. Check the spelling of the object or property name, or verify that the object is a collection.

Invalid ordinal (Error 452)

Your call to a dynamic-link library (DLL) indicated to use a number instead of a procedure name, using the #num syntax. However, an attempt to convert the expression num to an ordinal failed, or the num specified does not specify any function in the DLL. Check to make sure the expression represents a valid number, or call the procedure by name.

Specified DLL function not found (Error 453)

The dynamic-link library (DLL) in a user library reference was found, but the DLL function specified was not found within the DLL. An invalid ordinal may have been specified in the function declaration. Also, the DLL may have the right name but is not the version that contains the specified function.

Code resource not found (Error 454)

A call was made to a procedure in a code resource, but the code resource could not be found. This error can only occur on the Macintosh operating system.

Code resource lock error (Error 455)

A call was made to a procedure in a code resource. The code resource was found, but an error occurred when an attempt was made to lock the resource. Check for an error returned by HLock (for example, "Illegal on empty handle" or "Illegal on free block"). This error can only occur on the Macintosh operating system.

[Object] does not have [property name] property (Error 1000)

The property does not exist for this object. To see a list of properties for this object, choose Object Browser from the View menu, and click the question mark button in the Object Browser dialog box to display the Visual Basic Help topic for this object.

[Object] does not have [method name] method (Error 1001)

The method does not exist for this object. To see a list of methods for this object, choose Object Browser from the View menu, and click the question mark button in the Object Browser dialog box to display the Visual Basic Help topic for this object.

Missing required argument [argument] (Error 1002)

The method expected a required argument that does not exist. Add the argument to the code. To see a list of required arguments, choose Object Browser from the View menu, and click the question mark button in the Object Browser dialog box to display the Visual Basic Help topic.

Invalid number of arguments (Error 1003)

The method has the wrong number of arguments. This usually occurs when you use comma-separated position arguments (instead of named arguments), and you have too many arguments.

To see the valid arguments for this method, choose Object Browser from the View menu, and click the question mark button in the Object Browser dialog box to display the Visual Basic Help topic for this method.

[Method name] method of [object] class failed (Error 1004)

An external error occurred, such as a failure to read or write from a file. The method cannot be used on the object. Possible reasons include the following:

  • An argument contains a value that isn't valid. A common cause of this problem is an attempt to access an object that doesn't exist [for example, you tried to use Workbooks(5) when there were only three workbooks open].
  • The method cannot be used in the applied context. For example, some Range object methods require that the range contain data; if the range doesn't contain data, the method fails.
  • An external error occurred, such as a failure to read or write from a file.

For more information about the method, search Help for the method name.

Unable to set the [property name] property of the [object]class (Error 1005)

The property cannot be changed. Possible reasons include the following:

  • The value you're using for the property isn't valid (for example, you set a property to a string value, but the property requires a Boolean value).
  • The property is read-only and can not be written to.

Unable to get the [property name] property of the [object] class (Error 1006)

The property cannot be changed. Possible reasons include:

  • The value you are using for the property is not valid; for example, setting a property to a string value when the property requires a Boolean value.
  • The property cannot be used in the applied context. For example, the code ActiveChart.Legend.Font.Color = RGB(255, 0, 0) will cause this error if the active chart does not contain a legend.

REFERENCES

For more information about error codes, choose the Search button in Help and type:

   Trappable errors


Additional query words: 5.00 5.00a 5.00c 7.00
Keywords : kberrmsg kbprg
Version : WINDOWS:5.0,5.0c,7.0; MACINTOSH:5.0,5.0a,98
Platform : MACINTOSH WINDOWS
Issue type : kbhowto kbref


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.