The "VBA Runtime Error 68: Device Unavailable" in Excel typically occurs when your VBA code tries to access hardware, external devices (like printers, USB drives, or network shares), or COM objects that aren’t present or aren’t properly initialized. If your code fails silently or crashes with this error, the solution usually involves checking device connectivity, permissions, or removing invalid references. This guide shows you how to fix it step-by-step—no advanced coding required.
What You'll Need
- A working copy of Microsoft Excel (2010 or newer; Office 365 includes updates).
- Access to the device or network share your code targets (e.g., printer, USB, or shared folder).
- Administrator privileges if modifying system-wide settings (e.g., printer drivers).
- Optional: A backup of your workbook before making changes.
Step-by-Step
-
Identify the problematic code:
Open your VBA project (press
Alt + F11to open the VBA editor). Search for references to the device (e.g., printer, USB, or COM object) in theModule,UserForm, or event handler. Look for calls like:Printer.Print,ActiveWorkbook.Explore(for USB/folders), orCreateObject("Winmgmts")(for WMI devices). -
Check device status:
The error occurs if the device isn’t connected, disabled, or misconfigured. For example:
- Printers: Ensure the printer is turned on, connected, and installed in
Control Panel > Devices and Printers. Test printing a manual page from Excel (right-click the printer > "Print..."). If it fails, reinstall the printer driver from the manufacturer’s website. - USB drives/network shares: Verify the drive appears in
This PCor Windows Explorer. Right-click the folder in Excel > "Explore" to confirm access. If the drive is read-only, right-click > "Properties" > change permissions to allow read/write. - COM objects (e.g., serial ports, WMI): Unplug/replug peripherals (like serial ports) or restart the system. For WMI, check if the device service is running in
Services.msc(look for "WMI Control" or "Computer Management").
- Printers: Ensure the printer is turned on, connected, and installed in
-
Remove or update references:
Go to
Tools > References(VBA editor) and:- Uncheck any references related to the problematic device (e.g., "Microsoft Excel Object Library" if printing fails, but leave core Excel references like "Microsoft ActiveX Data Objects").
- If a reference was added incorrectly (e.g., a third-party COM component), delete it entirely.
- Restart Excel and retest the code.
- For printers, ensure the driver is installed and Excel trusts the printer.
- For USB devices, use the correct COM interface (e.g.,
Microsoft USB Device Interface).
-
Test in a clean environment:
Create a new VBA project (press
Alt + F11>Insert > Module) and paste just the problematic code snippet. If it works, the issue is likely a conflict in your original workbook (e.g., multiple references, corrupted macros). -
Check for permissions:
If the error occurs when accessing a network share or printer:
- Right-click the device in Excel > "Properties" > check "Security" tab for correct permissions.
- For shared folders, ensure the workbook user has "Full Control" on the share (via Windows File Explorer > right-click share > "Properties" > "Security").
- If using Excel’s API (e.g.,
ActiveWorkbook.Explore), test with a different folder path to rule out typos.
-
Update or reinstall the device driver:
If the error persists for hardware (e.g., printer, serial port):
- Go to
Control Panel > Devices and Printers> right-click the device > "Troubleshoot" - Uninstall the driver via
Device Manager > Printers/Other Devices > Uninstall Device. Restart Windows and reinstall the driver from the manufacturer’s site. - If the device is a COM object, update the registry (for advanced users) or use the device’s setup tool.
- Go to
If That Did Not Work
If none of the above resolves the error, try these advanced steps in order:-
Repair Excel:
Go to
Control Panel > Programs > Microsoft Office > Office Tools > Repair. Select "Quick Repair" first; if that fails, choose "Full Repair" (this may reinstall components but doesn’t delete data). -
Run Windows Update:
Click
Start > Settings > Windows Update > Check for updates. Install all critical updates, especially those for the printer/device category. -
Check Event Viewer for errors:
Open
Event Viewer > Windows Logs > Application. Look for entries related to Excel or the device. Errors like "Access Denied" or "COM component unavailable" will point to deeper issues (e.g., missing DLLs or security policies). -
Restore default settings:
As a last resort, reset Windows components related to the device:
- Open
regeditand navigate to:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows - Change the value of
"Appinit_DLLs"from an incorrect path (e.g., a third-party DLL) to empty. - Restart Windows and test Excel.
- Open
Common Mistakes
-
Ignoring device connectivity: Assuming a USB drive or printer is "connected" without verifying it’s recognized by Windows. Always check in
This PCorDevices and Printersbefore coding. - Overlooking permissions: Forgetting that shared folders or printers require explicit permissions in Windows. For example, a user account with "Read Only" access won’t work for writing.
-
Incorrect COM references: Adding the wrong reference (e.g., a printer driver instead of the correct COM object like
"Microsoft Excel Object Library"for basic operations). -
Modifying the registry without backup: Edits to
HKEY_LOCAL_MACHINEcan break system stability. Always back up the registry before making changes.
Tips
-
Test with a static path: Replace dynamic paths (e.g.,
"\\server\folder") with a hardcoded, working path to isolate whether the issue is the connection or the path syntax. -
Use error handling in VBA: Wrap problematic code in a
On Error Resume Nextblock or catch exceptions to debug silently failing operations:On Error Resume Next ' Your code here If Err.Number <> 0 Then MsgBox "Error: " & Err.Description End If - Disable antivirus during testing: Some security software blocks COM object access. Temporarily disable it to rule out interference.
- Check for 64-bit vs. 32-bit conflicts: If Excel is 64-bit but the device driver is 32-bit, or vice versa, the error may occur. Ensure compatibility by checking the device’s documentation.
Troubleshooting
-
Error persists after steps 1–5?
Try disabling Excel’s add-ins (close all extensions, go to
File > Options > Add-ins > Manage Microsoft Excel Add-ins > Uncheck all > Restart Excel). Some add-ins interfere with COM object access. - Device is listed as "Not Responding" in Device Manager? Right-click the device > "Update driver" > "Browser my computer for drivers" > select "Install from a list or specific location" > browse to the correct driver folder. If still stuck, uninstall the device entirely (Windows will reinstall it during next boot).
-
Error occurs only in certain macros?
Compare the failing macro with a working one. Differences might include:
- Hardcoded paths vs. relative paths.
- Missing error handling.
- Incorrect reference names.
-
Network share is "Offline" in Explorer?
Open
Command Prompt as Administratorand run:net use * /deleteto clear cached connections, then reconnect:net use Z: \\server\share /user:domain\username password
Frequently Asked Questions
Why does my Excel VBA code crash with "Device Unavailable" when printing?
The error often means the printer driver is missing, misconfigured, or Excel doesn’t trust the printer. First, verify the printer is installed in Devices and Printers. If it fails, reinstall the driver from the manufacturer’s website. In VBA, avoid using Printer.Print if the device isn’t reliable—use PDF export (ActiveWorkbook.ExportAsFixedFormat...) instead.
How can I access a USB drive from Excel without the "Device Unavailable" error?
Ensure the USB drive appears in This PC and has proper permissions. In VBA, use:
Workbooks.Explore "\\drive_letter\folder" (replace drive_letter with your drive, e.g., "F"). If the drive is read-only, change permissions in Windows File Explorer. For dynamic paths, store them in variables to avoid typos.
Is there a way to debug COM object errors in VBA without manual testing?
Yes, use the Err object in VBA to catch errors during execution. Example:
Sub DebugCOM()
On Error Resume Next
Dim objPrinter As Object
Set objPrinter = CreateObject("YourPrinterClass")
If Err.Number <> 0 Then
MsgBox "Failed: " & Err.Description
Else
objPrinter.PrintSomething
End If
End Sub
This logs errors without stopping the macro.
Why does my Excel file work fine on one PC but fails on another with this error?
Usually due to:
- The second PC not having the same device driver installed.
- Different Windows permissions (e.g., shared folders accessible only to local users).
- VBA references pointing to a missing COM object that’s only present on one machine.
Can I use this error for logging purposes in VBA?
Yes, wrap error-handling blocks around device-access code. For example:
Sub LogDeviceAccess()
Try:
' Code that may fail (e.g., CreateObject)
LogSuccess "Device accessed successfully"
Catch ex As Exception:
LogError ex.Message
End Sub
Use a separate LogSuccess/LogError function to save logs to a sheet or file.
What if I’m using a third-party COM object (e.g., for data extraction)?
If the object was added via Tools > References, uncheck it in the VBA editor and reinstall it. If the error persists, the object may have a version mismatch or missing dependencies. Check the vendor’s documentation for setup instructions.