The "VBA Runtime Error 382: Property can't be set at runtime" occurs when a VBA module attempts to modify a property of an object (like a worksheet, workbook, or control) that’s locked or inaccessible during execution. This often happens in Excel, Word, or Access macros, where objects are in a read-only state or the underlying system prevents modification. The fix depends on whether the issue stems from a misconfigured property, a timing problem, or an external dependency. Below is a step-by-step guide to diagnose and resolve it, including common triggers, troubleshooting, and alternative workarounds.

What You'll Need

  • A working Excel, Word, or Access application (v2013 or newer recommended)
  • Basic familiarity with VBA editor (Alt+F11) and debugging tools
  • Administrator or admin-level permissions for registry tweaks (rarely needed)
  • Access to the VBA project file (.vbproj or .xlsm)
  • A backup of your workbook/macro project before making changes

Step-by-Step

  1. Identify the problematic module: Open your VBA project (press Alt+F11). Navigate to the module where the error occurs by selecting the sheet or object (e.g., ThisWorkbook, UserForm1) in the Project Explorer. Right-click the module, then View Code. Add this debug line at the top: Debug.Print Err.Number & ": " & Err.Description. Run your macro again and observe the exact error code. Error 382 typically appears in these contexts:
    • Attempting to set a property on a frozen or invisible worksheet.
    • Modifying a control’s value after the form is being closed.
    • Calling a method that triggers the object being locked (e.g., after a save operation).
    If you see a different error code (e.g., 438, "Object doesn’t support this property"), the fix may differ slightly. For example:
    1. Error 438: Use Try/Catch blocks or check object availability.
    2. Error 5: Invalid procedure call: Ensure you’re calling the correct method name.
  2. Remove or replace the problematic property: If the error is due to a direct object modification (e.g., ws.Visible = True), replace it with a conditional check. For example:
            If Not IsEmpty(Me) Then
                Me.Visible = True
            End If
            
    For Excel worksheets, try:
            If Not ws.IsLocked Then
                ws.Visible = True
            End If
            
    Alternatively, use the EnableEvents flag to defer property changes. In your macro, add a delay or event handler:
            Application.EnableEvents = False
            ' Your code here
            Application.EnableEvents = True
            
  3. Check for external dependencies: If the error occurs during file operations (e.g., saving, loading), ensure the file is unlocked. In VBA:
            Dim fso As FileSystemObject
            Set fso = New FileSystemObject
            If Not fso.FileExists("C:\path\to\file.xlsm") Then
                MsgBox "File not found or locked!"
                Exit Sub
            End If
            
    For Office apps, check if another process (e.g., PowerPoint viewer) holds the file open. Use Task Manager to force-close it.
  4. Fix timing issues (for forms or UI events): If the error occurs in a UserForm or button click handler, rearrange your code. For example:
    1. Move form initialization to a separate subroutine.
    2. Use timers or DoEvents (caution: DoEvents is risky—only use it sparingly for UI delays).
    3. Ensure controls exist before accessing them. Replace: Me.Button1.Value = "Click" with:
                      If Me.Controls.Item("Button1") Is Nothing Then
                          CreateButton
                      End If
                      
  5. Update VBA references (if applicable): If the error persists after checking properties manually, ensure your VBA references match the object’s library. Go to Tools > References (Alt+F11 > Tools > References) and check:
    1. Excel Objects (for Excel macros).
    2. Microsoft Forms (for UserForms).
    3. Microsoft Office x.x Object Library (for Word/Access).
    Remove outdated or incorrect references. If you’re using a custom object, verify it’s registered.
  6. Recreate the macro from scratch: If the error is structural (e.g., a recursive call or circular reference), rewrite the problematic section. Use an IDE like Visual Studio for VBA to avoid syntax mistakes. If that did not work:
    1. Check for macros that conflict with your project (Windows Task Manager > Excel process).
    2. Run Clean Up Code (Tools > Make Temporary Objects Visible) to identify hidden objects causing locks.
    3. Enable debug logging by adding:
                      Private Sub Application_Open()
                          LogFile "C:\Temp\VBAError.log"
                      End Sub
                      
      to track runtime state.

Common Mistakes

  • Assuming an object is "unlocked" when it isn’t: Worksheets can be locked via Sheets("Sheet1").Unprotect Password "..."—always verify with ws.Unprotect before modifying.
  • Accessing controls before they’re loaded: In UserForms, use Me.Invalidate or Me.Refresh instead of direct property access (e.g., Me.Label1.Text).
  • Ignoring Office event handlers: Macros like Application.WorkbookActivate must not trigger properties on locked objects. Use Application.EnableEvents = False temporarily.
  • Overlooking file locks in shared environments: In multi-user setups, Excel may block changes during saves. Use ThisWorkbook.SaveAs instead of ThisWorkbook.Save.

Tips

  • Use conditional checks: Replace direct property assignments with If Not IsNull(ws.Name) Then ws.Visible = True. This prevents errors on null/empty objects.
  • Avoid DoEvents in production code: It can deadlock the UI. Use Application.Wait Now + TimeValue("0:00:01") for delays instead.
  • Test in a minimal environment: Remove unrelated code to isolate the problematic section. If it works in a fresh module, the issue is likely a hidden dependency.
  • Check for 32-bit/64-bit conflicts: If you’re mixing Excel 32-bit (old) and 64-bit (new), some properties may fail. Update all Office versions to the same architecture.
  • Use a debug breakpoint: Place a breakpoint on the line where the error occurs. Step through the code to see which object or property is locked.

Troubleshooting

  1. If the error appears randomly: Check for pending updates. Run Windows Update and restart Excel. If the issue persists, try:
    • Repair Office via Control Panel > Programs > Microsoft Office > Change > Repair.
    • Run Excel in Safe Mode: Excel /safe from Command Prompt.
  2. If the error is tied to a specific object (e.g., a chart): Right-click the chart > Chart Design > Select Data.... Check if the data source is corrupted. Delete the chart and recreate it.
  3. If the macro fails during export/import: Test the macro with a blank workbook first. Add this before exporting:
            Dim data As Variant
            Set data = ThisWorkbook.Sheets("Sheet1").Range("A1:C10").Value
            ThisWorkbook.SaveAs "C:\Temp\Backup.xlsm"
            
    Then re-import the backup.
  4. If you’re on a shared PC and other users fail too: Ask IT to check if macros are restricted via group policies (e.g., gpedit.msc > Computer Configuration > Administrative Templates > Windows Components > Microsoft Office > Security Settings). Disable macro enforcement if safe.
  5. If nothing works and the macro is critical: Rewrite the problematic section using a Try/Catch block:
            On Error Resume Next
            ws.Visible = True
            If Err.Number <> 0 Then
                MsgBox "Failed to set visibility. Error: " & Err.Description
            End If
            On Error GoTo 0
            

Frequently Asked Questions

Why does my VBA macro crash with "Property can't be set at runtime" when running in Word?

The issue often stems from Word’s security settings or a locked document state. Ensure your macro references the correct Word object library (Microsoft Word x.x Object Library in Tools > References). Also, avoid modifying controls (e.g., TextBox1.Font) on a form that’s being closed. Use Application.EnableEvents = False before the problematic line and EnableEvents = True afterward.

How can I prevent this error from happening in Excel when saving files?

Use explicit file locking. Replace: ThisWorkbook.Save with:

If ThisWorkbook.Path <> "" Then
    ThisWorkbook.SaveAs ThisWorkbook.Path & "\" & ThisWorkbook.Name & ".tmp"
    ThisWorkbook.Close SaveChanges:=False
    My.Computer.FileSystem.RenameFile ThisWorkbook.Path & "\" & ThisWorkbook.Name & ".tmp", ThisWorkbook.Path & "\" & ThisWorkbook.Name
Else
    ThisWorkbook.Save
End If
This avoids concurrent save conflicts.

Is there a way to debug this error without editing the VBA code?

Yes. Use the VBA debugger:

  1. Press F8 to step through the code line by line.
  2. When the error occurs, inspect the Err.Number and Err.Description in the Immediate Window (Ctrl+G).
  3. Check the Watch window for object references (e.g., ws.Name). If it’s Nothing, the object hasn’t loaded.

Why does my UserForm’s button click event fail with Error 382?

Likely causes include:

  • The form isn’t loaded yet (access before Me.Show).
  • A control’s parent is being destroyed (e.g., another form closes mid-event). Use If Me.Parent Is Nothing Then Exit Sub.
  • The form is modal, and the button is disabled until interactive.
Try this in your button’s click handler:
If Me.IsModal Then Exit Sub
If Me.Visible = False Then Me.Show
Me.Button1.Value = "Clicked"

Can I force a property change to work despite the error?

Only if you know the exact object and property involved. For example:

  1. Use reflection via VBA’s TypeName to dynamically check properties.
  2. For Excel, try ws.Cells(1, 1).Value = "Test" instead of ws.Range("A1").Value if the range is locked.
However, this is unreliable and may break other parts of your code.

What if the error is caused by a third-party add-in?

Disable all add-ins temporarily by enabling Safe Mode in Excel:

  1. Open Excel with Excel /safe from Command Prompt.
  2. Test your macro. If it works, re-enable add-ins one by one.
If the issue is Office-specific, contact the add-in developer with the error details.