Fix Run-time Error 509: WordBasic.DisableAutoMacros in Protected Word Documents
Question details
The user needs a solution for run-time error 509 that occurs when trying to disable auto macros programmatically on a protected active document.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Running batch processing via a VSTO add-in where the code attempts to disable auto-executing macros across thousands of protected documents.
- Observed behavior
- Calling `WordBasic.DisableAutoMacros` triggers run-time error 509 because the command is unavailable when a protected document is the active window.
Ensure you have access to modify your VSTO add-in source code and verify that your application has sufficient permissions to silently create and close temporary documents during batch processing.
Use a Temporary Unprotected Document in the VSTO Add-in
Create and activate a temporary unprotected document within your code to safely call the DisableAutoMacros command without triggering the error.
Because `WordBasic.DisableAutoMacros` is blocked when the active document has protection enabled, shifting the application's focus to an unprotected document temporarily bypassing this restriction.
This method is highly scalable and perfect for unattended batch processing of thousands of files.
Modify your VSTO add-in code to programmatically create a new, blank, unprotected Word document before the macro-disabling step.
Set the newly created unprotected document as the active document in the Word application instance.
Execute the `WordBasic.DisableAutoMacros` command now that the active document is unprotected. The command will apply to the application level successfully.
Close the temporary document without saving it, and proceed with processing your protected documents.
When you need to re-enable the setting at the end of the batch run, repeat the process of opening, activating, and closing a temporary unprotected document.

Manually Bypass AutoMacros Using the Shift Key
Manually prevent AutoMacros from running by holding the Shift key when opening individual documents.
Try WPS Office for Seamless Document Management and Macro Compatibility
If you frequently encounter complex VBA limitations or macro execution errors in Microsoft Word, consider switching to WPS Office. It provides robust macro support, excellent format compatibility, and a lightweight environment that speeds up large-scale document processing tasks.

Frequently Asked Questions
What causes run-time error 509 in Word VBA?
Run-time error 509 occurs when a specific VBA command is unavailable in the current context. In this scenario, calling `WordBasic.DisableAutoMacros` fails because the active document is protected, which natively restricts certain application-level commands.
Can I disable AutoMacros in Word without using VBA or a VSTO add-in?
Yes, you can manually prevent AutoMacros from executing by pressing and holding the Shift key on your keyboard while double-clicking to open a document. The macros will remain disabled for that specific file session.
Why shouldn't I use the Shift key method for batch processing?
The Shift key workaround requires continuous physical interaction for every single document opened. If you are processing thousands of documents, this method cannot be automated and would take hours of manual effort, making the VSTO temporary document workaround a much better solution.




