How to Fix Word VBA Run-Time Error 4198 When Opening or Writing Files
Question details
The user encounters a run-time error 4198 when running a VBA macro that interacts with file opening, writing, or conversion processes.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Automating document tasks such as opening files, performing a mail merge, or saving documents to PDF formats using VBA macros.
- Observed behavior
- The macro execution halts, displaying 'Run-time error 4198: Command failed', typically because the target file is locked or the previous operation has not finished.
Ensure you have saved a backup copy of your VBA script and verify that the target files or output folders are not currently open in another program.
Verify File Paths and Clear Background Processes
Ensure the target file is not locked by a hidden instance of Word, Acrobat, or another application, and that the path is valid.
Run-time error 4198 often triggers when a VBA macro tries to write to or open a file that is already locked by another process or when the specified file path does not exist.
Press Ctrl + Shift + Esc to open the Task Manager. Look for any ghost 'WINWORD.EXE' or Adobe Acrobat processes running in the background and click 'End Task'.
Review your VBA code to ensure the file path is absolute and fully qualified (e.g., C:\Users\Name\Documents\File.docx) and that the destination folder actually exists.
Navigate to the file in File Explorer, right-click it, select 'Properties', and ensure the 'Read-only' attribute is unchecked.
Add Synchronization Delays to the VBA Code
Pause the macro execution to allow Word or Acrobat enough time to finish asynchronous tasks like conversions or mail merges.
Release COM Objects Properly
Ensure all document and application objects are properly closed and released in the macro to prevent residual file locks.
Try WPS Office for a Smooth and Reliable Document Experience
If troubleshooting complex Microsoft Word VBA run-time errors is slowing you down, consider switching to WPS Office. It is a highly compatible, free, and lightweight alternative that seamlessly handles Microsoft Office formats and provides robust tools for everyday document automation.
- 1. Download WPS Office: Visit the official WPS Office website and download the free installer for your operating system.
- 2. Install and Launch: Run the setup file and follow the on-screen instructions to install the suite, then open WPS Writer.
- 3. Open Your Documents: Drag and drop your existing .docx or .doc files directly into the WPS interface to continue your work without formatting loss.

Frequently Asked Questions
What does Run-time error 4198 'Command Failed' mean in Word VBA?
This error is a generic failure message indicating that Word could not execute the requested VBA command. It most commonly occurs during file operations when a file is locked, inaccessible, or when a previous background operation (like a PDF conversion) hasn't finished.
How can I tell if my output file is locked by another process?
You can check for file locks by manually trying to delete or rename the file in Windows File Explorer. If Windows prompts that the file is open in another program, it is locked. Use Task Manager to find and close hidden Word or Acrobat processes.
Can converting a Word document to PDF trigger error 4198?
Yes. If your VBA macro uses Adobe Acrobat or Word's native PDF exporter to convert a document, the process might run asynchronously. If the macro attempts to close or move the file before the conversion completes, error 4198 will trigger.
Why does my macro work perfectly sometimes but fail with error 4198 at other times?
This inconsistency is usually a synchronization issue. Depending on your computer's current CPU load and disk speed, an asynchronous task might finish quickly enough on one run but take slightly longer on another, causing the next VBA command to fail. Adding a brief pause (Application.Wait) often resolves this.




