Runtime Error 91, also known as “Object variable or With block variable not set,” usually appears when an application or VBA script tries to access an object that has not been properly initialized or assigned. You may encounter this error while using Microsoft Excel, Access, or other Windows applications. It can happen because of missing object references, corrupted application files, incomplete software installations, or coding issues. In some cases, outdated software or missing dependencies can also trigger it. In this guide, you’ll learn what causes Runtime Error 91 and how to troubleshoot it using practical solutions.
What Is Runtime Error 91 in Windows?
Runtime Error 91 is a Visual Basic (VB/VBA) error that occurs when a program tries to use an object variable that has not been assigned a valid object reference.
In simple terms, an application expects a particular object to be available, but that object hasn’t been properly initialized. When the program tries to access it, Windows displays the following message:
Run-time error ’91’: Object variable or With block variable not set.
This error is commonly associated with Microsoft Excel macros, Access databases, and applications developed using Visual Basic. It can also appear when third-party software encounters a programming issue or fails to load a required component.
However, the exact cause depends on the software you’re using.
- Missing object references: A VBA script may try to access an object that was never created or assigned.
- Corrupted application files: Damaged program files or settings can prevent an application from initializing objects correctly.
- Incomplete software installation: Missing components or dependencies can interfere with how an application works.
- Outdated software: Older application versions may contain bugs or compatibility issues that trigger runtime errors.
- Incorrect VBA code: A macro that references a deleted worksheet, unavailable workbook, or invalid object can produce Runtime Error 91.
1. Restart the Affected Application and Your PC
Sometimes, a temporary application glitch or an incomplete background process can prevent a program from initializing objects correctly. Restarting the application can clear these temporary issues and let it reload the required components.
- Press Ctrl + Shift + Esc to open Task Manager.
- Under the Processes tab, locate the application showing Runtime Error 91.
- Right-click it and select End task.
- Close any related background processes if they are still running.
- Restart your computer and open the application again.

Check whether the error appears again.
2. Update the Application to the Latest Version
An outdated application may contain bugs or compatibility issues that prevent certain objects and components from loading properly. Updating the affected program can fix known issues and improve compatibility with Windows 11 and Windows 10.
Open the application and look for an update option under its Help, File, or Settings menu. Install any available updates and restart the program.
If you encounter Runtime Error 91 in Microsoft Office applications:
- Open Excel or another Office application.
- Click File and select Account.
- Under Product Information, click Update Options.
- Select Update Now.
- Allow Office to download and install available updates.
Once the update is complete, reopen the affected application and check whether the problem is resolved.
3. Run the Application as an Administrator
Some applications require elevated permissions to access files, system resources, or other components. If the program cannot access the resources it needs, certain operations may fail and trigger runtime errors.
Running the application with administrator privileges can help rule out permission-related problems.
- Close the application showing Runtime Error 91.
- Press the Windows key and search for the affected application.
- Right-click the application and select Run as administrator.
- Click Yes if the User Account Control prompt appears.
- Repeat the action that previously triggered the error.

If the error disappears, insufficient permissions may have contributed to the problem. You can also configure the application to always run with administrator privileges:
- Right-click the application’s shortcut and select Properties.
- Open the Compatibility tab.
- Check Run this program as an administrator.
- Click Apply and then OK.
Note: Only enable this option for applications you trust. Running software with administrator privileges gives it additional access to your system.
4. Repair Microsoft Office
If Runtime Error 91 appears while using Excel, Word, Access, or another Microsoft Office application, damaged Office installation files may be responsible.
Microsoft Office includes built-in repair options that can fix missing or corrupted program components without requiring a complete reinstallation.
- Press Windows + R, type
appwiz.cpl, and press Enter. - Find Microsoft 365 or Microsoft Office in the Installed Programs list.
- Right-click it and select Change.
- Select Quick Repair and click Repair.
- Follow the on-screen instructions and restart your computer.
If Quick Repair doesn’t resolve the issue, repeat the process and select Online Repair instead.
Online Repair performs a more thorough repair and may take longer. Make sure you have a working internet connection before starting it.
Open the affected Office application again and check whether Runtime Error 91 still appears.
5. Check and Fix Missing References in VBA
If Runtime Error 91 appears when running a macro in Microsoft Excel or Access, the problem may be related to an object that hasn’t been properly assigned in the VBA code.
For example, a macro may try to access a worksheet, workbook, or range that hasn’t been initialized. Review the VBA code to identify the missing reference.
- Open the Excel workbook or Access database where the error occurs.
- Press Alt + F11 to open the Visual Basic Editor.
- Select Debug from the menu and click Compile VBAProject.
- If the editor highlights an error, review the affected code.
- Look for object variables that are being used without first being assigned.
- Make sure the required objects are properly initialized before the code accesses them.
For example, a VBA object variable should be assigned using the Set statement:
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")
ws.Range("A1").Value = "Test"
Here, Set assigns the worksheet object to the variable before the code tries to use it.
If you are not familiar with VBA, avoid changing unfamiliar code. Contact the macro developer or check whether an updated version of the workbook or application is available.
6. Reinstall the Affected Application
If the error continues after trying the previous solutions, the application’s installation files may be damaged or some required components may be missing. Reinstalling the program can replace these files and restore its default settings.
Before uninstalling, back up important documents, application settings, and license information if necessary.
- Press Windows + I to open Settings.
- Go to Apps > Installed apps in Windows 11 or Apps > Apps & features in Windows 10.
- Find the application showing Runtime Error 91.
- Click the three-dot menu (Windows 11) or select the application (Windows 10).
- Choose Uninstall and follow the instructions.

- Restart your computer.
- Download the latest version from the application’s official website and install it.
After installation, open the program and check whether the error has disappeared.
Important: If the error occurs in an Excel or Access VBA project, reinstalling the application may not fix incorrectly written macro code. In that case, you need to correct the VBA code itself.
7. Check for Missing or Broken References in VBA
This is slightly different from checking object assignments in Method 5. VBA projects can also contain missing library references, which may prevent macros from working correctly.
- Open the affected Excel workbook or Access database.
- Press Alt + F11 to open the Visual Basic Editor.
- Click Tools > References.
- Look for any entry marked MISSING.
- If you find one, identify the required library and restore or replace the reference with the correct version.
- Click OK, then select Debug > Compile VBAProject.
Don’t simply uncheck a missing reference without confirming whether the VBA project needs it.
8. Run System File Checker and DISM
If Runtime Error 91 occurs across multiple applications, damaged Windows system files may be contributing to the problem. Running DISM and System File Checker can help repair the Windows image and replace corrupted system files.
- Search for Command Prompt in Windows Search.
- Right-click it and select Run as administrator.
- Run the following command:
DISM /Online /Cleanup-Image /RestoreHealth
- Wait for the operation to finish.
- Next, run:
sfc /scannow
6. Allow the scan to complete and restart your computer.

These tools won’t correct an improperly assigned VBA object, but they can help rule out Windows system file corruption.
Final Thoughts
Runtime Error 91 usually occurs when an application or VBA script tries to access an object that hasn’t been properly initialized or assigned. The problem is often related to incorrect VBA code, missing object references, or damaged application files.
Start by restarting the affected program and installing available updates. If the error appears in Excel or Access, check the VBA code and missing references. For other application-related issues, repairing or reinstalling the affected program may help. If the problem occurs across multiple applications, run DISM and SFC to rule out corrupted Windows system files.
Frequently Asked Questions
Runtime Error 91 means an application or VBA script is trying to use an object variable that hasn’t been assigned a valid object reference. It commonly occurs when running macros in Microsoft Excel or Access.
Start by restarting Excel and installing the latest Office updates. If the error continues, open the VBA Editor using Alt + F11, check the affected macro, and make sure all required object variables are properly assigned using the Set statement.
Yes, a missing or broken library reference can interfere with a VBA project. Open the Visual Basic Editor, select Tools > References, and check whether any required library is marked as MISSING.
No. Runtime Error 91 is generally a programming or application-related error, not a direct sign of malware. However, if you notice other unusual system behavior, running a full scan with Microsoft Defender Antivirus is a sensible precaution.
Yes, reinstalling the affected application can replace damaged or missing program files. However, if the error is caused by incorrectly assigned VBA objects or faulty macro code, reinstalling the application alone may not resolve it.






