VBA Runtime Error 393 occurs when your code attempts to retrieve a value from a property that is currently unavailable or cannot be executed in the current state of the application. This usually happens because the object you are referencing is not fully initialized, is in a "read-only" state, or the specific property is only accessible during a certain event or phase of the program's execution.
What You'll Need
- The Excel, Word, or Access file containing the VBA project.
- Access to the Visual Basic Editor (VBE).
- A backup copy of your workbook or database (recommended before modifying code).
Step-by-Step
- Identify the Failing Line: When the error pops up, click the Debug button in the error dialog box. VBA will highlight the specific line of code in yellow that is triggering the error.
- Verify Object Initialization: Check if the object being called has been properly set. If you are using a variable for an object, ensure you have used the
Setkeyword (e.g.,Set myRange = Range("A1")) before attempting to get a property from it. - Check Application State: Determine if the property you are calling requires the application to be in a specific mode. For example, some properties in UserForms cannot be accessed until the form is fully loaded using
UserForm.Show. If the code is running in theInitializeevent, try moving the logic to theActivateevent. - Validate Object Existence: Ensure the object actually exists at the moment the code runs. If your code refers to a specific sheet name or a named range that was deleted or renamed, the "Property Get" will fail because the object is null.
- Test with a Breakpoint: Place a breakpoint (F9) on the line immediately preceding the error. Run the code and hover your mouse over the object variable to see if it is
Nothing. If it isNothing, you must trace back to where the object should have been assigned. - Implement Error Handling: Wrap the problematic property call in a basic error handler to prevent the application from crashing. Use
On Error Resume Nextimmediately before the line, followed by a check to see if the operation failed, thenOn Error GoTo 0to reset error handling.
Common Mistakes
- Calling Properties Too Early: Attempting to get a property of a UserForm control before the form is visible or fully initialized.
- Assuming Object Persistence: Assuming an object variable remains "Set" after a global reset or after the code has exited a specific procedure.
- Incorrect Scope: Declaring an object as a local variable in one sub and trying to access its properties in another sub without passing the object as an argument.
- Referencing Closed Workbooks: Trying to get a property from a range or sheet in a workbook that has been closed by another part of the script.
Tips
- Use Option Explicit: Always place
Option Explicitat the very top of your modules. This forces you to declare all variables, making it much easier to spot typos in object names that lead to runtime errors. - Explicit Referencing: Avoid using
ActiveSheetorSelection. Instead, use explicit references likeThisWorkbook.Sheets("Data").Range("A1"). This ensures the "Property Get" is targeting the correct object regardless of what the user has clicked. - Check for Nothing: Before calling a property on an object variable, use an
If Not myObject Is Nothing Thenblock to ensure the object is valid.
Troubleshooting
If the steps above do not resolve the issue, try these additional checks:
- Restart the Application: Sometimes the VBA project becomes unstable in memory. Save your work, close the application entirely, and restart it.
- Compile the Project: In the Visual Basic Editor, go to the Debug menu and select Compile VBAProject. This will highlight syntax errors that might be causing logical failures during runtime.
- Check Library References: Go to Tools > References. Look for any items marked as "MISSING:". If a required library is missing, the property get for objects belonging to that library will fail.
- Simplify the Call: If you are using a complex nested reference (e.g.,
Workbooks(1).Sheets(1).Range("A1").Value), break it into separate variables:Set wb = Workbooks(1)Set sh = wb.Sheets(1)Set rg = sh.Range("A1")
This allows you to see exactly which "link" in the chain is causing the Error 393.
Frequently Asked Questions
Why does this happen in UserForms but not in standard modules?
UserForms have a specific lifecycle. Certain properties are not available during the Initialize event because the window hasn't been rendered yet. Moving the code to the Activate event usually fixes this.
Is Error 393 the same as Error 91 (Object variable not set)?
They are related but different. Error 91 means the object is Nothing. Error 393 means the object exists, but the specific property you are trying to "Get" cannot be accessed at this moment.
Can a protected sheet cause this error?
Yes. If your code attempts to get a property that is restricted when a sheet is protected, or if it attempts to modify a property via a "Get" operation that triggers a protected event, this error can occur.
Does updating Office fix Runtime Error 393?
Rarely. This is almost always a logic error in the VBA code regarding the timing or state of an object, rather than a bug in the Office installation itself.
Will using "On Error Resume Next" fix the underlying problem?
No. It only hides the error from the user. While it prevents the crash, the property will not be retrieved, and your variables will remain empty, which may cause further errors later in the script.