• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Error Handling in VBA with Custom Messages

AQ_Awan

New Member
What are some best practices for implementing error handling in VBA? I'd like to show custom error messages based on different types of errors that might occur in my code.
 
ERROR NUMBERS & DESCRIPTIONS
Error #Error MessageDescription
3Return without GoSubOccurs when a Return statement is encountered outside of a subroutine that was called using GoSub.
5Invalid procedure callOccurs when a procedure is called with an invalid argument.
6OverflowHappens when a numeric expression exceeds the range of its data type.
7Out of memoryOccurs when the system has insufficient memory to execute a procedure.
9Subscript out of rangeHappens when trying to access an array element that doesn't exist (index out of bounds).
10Array is fixed or temporarily lockedOccurs when trying to modify an array that is fixed or locked.
11Division by zeroHappens when attempting to divide by zero.
13Type mismatchOccurs when a value doesn't match the expected data type.
14Out of string spaceHappens when there isn't enough memory to perform a string operation.
16Expression too complexOccurs when an expression is too complex to be evaluated.
17Can't perform requested operationOccurs when attempting to perform an operation that is not allowed in the current context.
28Out of stack spaceHappens when the call stack exceeds its limit.
35Sub, Function, or Property not definedOccurs when trying to call a subroutine, function, or property that doesn't exist.
47Too many DLL application clientsOccurs when the application tries to open more DLLs than it can handle.
48Error in loading DLLHappens when a DLL file that's required by the application is missing or corrupted.
49Bad DLL calling conventionOccurs when a DLL function is called with the wrong calling convention.
51Internal errorIndicates an internal error in VBA runtime.
52Bad file name or numberOccurs when trying to perform file I/O operations with an invalid file name or number.
53File not foundHappens when trying to access a file that doesn't exist.
54Bad file modeOccurs when trying to perform file I/O operations with an invalid file mode.
55File already openHappens when trying to open a file that's already open in another process.
57Device I/O errorIndicates an error with the input/output (I/O) operation.
58File already existsHappens when trying to create a file that already exists.
59Bad record lengthOccurs when trying to read or write records with an invalid length.
61Disk fullHappens when the disk is full and no more data can be written to it.
62Input past end of fileOccurs when trying to read past the end of a file.
63Bad record numberHappens when trying to read or write records at an invalid record number.
64Bad file nameOccurs when trying to perform file I/O operations with an invalid file name.
67Too many filesIndicates that the application has exceeded the maximum number of open files.
68Device unavailableHappens when the device requested for an I/O operation is not available.
70Permission deniedOccurs when the application doesn't have the necessary permissions to perform an operation.
71Disk not readyHappens when trying to perform file I/O operations on a disk that is not ready.
74Can't rename with different driveOccurs when trying to rename a file with a different drive.
75Path/File access errorIndicates an error when trying to access a file or path.
76Path not foundHappens when trying to access a path that doesn't exist.
91Object variable not setOccurs when an object variable isn't initialized (set to an object).
92For loop not initializedHappens when trying to use a For loop that hasn't been initialized.
94Invalid use of NullOccurs when trying to use a Null value in a context where it's not allowed.
95Invalid use of NullOccurs when trying to use a Null value in a context where it's not allowed.
96Unable to sink events of object because the object is already firing eventsOccurs when trying to sink events of an object that is already firing events.
97Can't call Friend procedure on an object that is not an instance of the defining classOccurs when trying to call a Friend procedure on an object that is not an instance of the defining class.
98A property or method call cannot include a reference to a private object, either as an argument or as a return valueOccurs when trying to reference a private object in a property or method call.
99For Each...Next not initializedHappens when trying to use a For Each loop that hasn't been initialized.
100Cannot create AutoRedraw imageOccurs when trying to create an AutoRedraw image.
101Application-defined or object-defined errorGeneral error message often seen when working with Excel objects.
32767User-defined errorUsed to indicate user-defined errors.
 
Back
Top