VBA Runtime Error 423 occurs when the code attempts to call a property or method that does not exist for the specific object being used. To fix this, you must identify the line of code causing the crash and ensure that the object variable is correctly declared and that the method name is spelled exactly as required by the VBA library.
What You'll Need
- The Microsoft Office application containing the macro (Excel, Word, Access, etc.).
- Access to the Visual Basic for Applications (VBA) Editor.
- The specific line of code highlighted in yellow when the error occurs.
Step-by-Step
- Locate the Erroring Line: When the "Runtime Error 423" dialog box appears, click the Debug button. This will open the VBA Editor and highlight the problematic line of code in yellow.
- Verify Spelling and Syntax: Check the method or property name following the object. VBA is sensitive to spelling. For example, calling
Range("A1").Valueeinstead ofRange("A1").Valuewill trigger this error. Ensure there are no typos and that the capitalization matches the standard library (though VBA often auto-corrects case, manual typos in the name itself will not). - Check Object Type Declaration: Look at how the object was declared (the
Dimstatement). If you declared a variable as a genericObjector a different class than intended, the compiler may not recognize the method.- Incorrect:
Dim mySheet As Workbook(then trying to usemySheet.Cells, which is a Worksheet property). - Correct:
Dim mySheet As Worksheet.
- Incorrect:
- Inspect Missing References: If the method belongs to an external library (like Outlook, Word, or a custom DLL), the reference might be broken.
- In the VBA Editor, go to the Tools menu and select References.
- Look for any items marked as MISSING: [Library Name].
- Uncheck the missing reference and find the current version of that library in the list to check it instead.
- Validate Object Initialization: Ensure the object has been properly set using the
Setkeyword before the method is called. If the object isNothingor has not been instantiated, calling a method on it can sometimes result in a 423 error depending on the object type. - Test with IntelliSense: Delete the period (dot) after your object variable and re-type it. If the IntelliSense dropdown menu appears and the method you are trying to use is not in the list, the method does not exist for that object type. You will need to change the object type or use a different method.
Common Mistakes
- Confusing Objects: Using a
Workbookobject when you meant to use aWorksheetobject. Workbooks do not have aRangeproperty, but Worksheets do. - Version Mismatches: Using a method that exists in a newer version of Office (e.g., Office 365) while running the code on an older version (e.g., Office 2013) that does not support that specific property.
- Incorrect Library References: Forgetting to enable the "Microsoft Scripting Runtime" or "Microsoft Outlook Object Library" when using FileSystemObjects or MailItems.
- Typing Errors: Simple misspellings of common properties, such as writing
.TextValueinstead of.Textor.Value.
Tips
- Use Option Explicit: Always place
Option Explicitat the very top of your modules. This forces you to declare all variables, which helps prevent errors caused by misspelled variable names that VBA would otherwise treat as new, empty variables. - Early Binding vs. Late Binding: If you distribute your macro to other users with different Office versions, consider using Late Binding (declaring objects
As Object) to avoid "Missing Reference" errors, though you lose the benefit of IntelliSense during development. - Break Down Complex Lines: Instead of nesting multiple calls (e.g.,
Workbooks("Book1").Sheets("Sheet1").Range("A1").Value), break them into separate variables. This makes it easier to see exactly which object is failing.
Troubleshooting
If the steps above do not resolve the issue, try these advanced checks:
- Compile the Project: Go to the Debug menu in the VBA Editor and select Compile VBAProject. This will often find syntax errors or missing references that aren't triggered until the code actually runs.
- Check for Name Conflicts: Ensure you haven't named a variable or a procedure the same name as a built-in VBA property or method. This can confuse the compiler and lead to "Method Not Found" errors.
- Restart the Application: In some rare cases, the VBA project becomes corrupted in memory. Save your work, close the application entirely, and restart it.
- Verify Object State: Use the Immediate Window (Ctrl+G) to check the type of the object at runtime. Type
?TypeName(yourObjectName)and press Enter to see what VBA thinks the object is.
Frequently Asked Questions
Is Error 423 the same as Error 438?
They are very similar. Error 438 ("Object doesn't support this property or method") is more common. Error 423 typically occurs when the property is found but cannot be accessed or is not applicable to the current state of the object.
Why does my code work on my computer but give Error 423 on another?
This is almost always due to a missing reference or a different version of Office. The other computer likely lacks a specific library (like a database driver or an Office app library) that your code relies on.
Can a typo in a variable name cause this?
Yes. If you have a typo in the object variable name and you aren't using Option Explicit, VBA creates a new empty variable. Calling a method on an empty variable can trigger this error.
Does this error happen with UserForms?
Yes. If you attempt to call a property of a control (like a TextBox) but have misspelled the control's name or are treating a Label as a TextBox, Error 423 can occur.
How do I find the correct method name for an object?
The best way is to use the IntelliSense dropdown by typing the object name followed by a dot (.). If it doesn't appear there, consult the official Microsoft Learn documentation for that specific object class.