VBA & Macro Problems

How to Pass an AppleScript Variable to Microsoft Word VBA to Delete Custom Properties

Adam DavisAdam Davis Oct 19, 2026 869 views

Question details

The user needs to pass a custom document property name as a variable from AppleScript to a Microsoft Word VBA macro so the VBA script can delete the property.

How to Pass an AppleScript Variable to Microsoft Word VBA
Product
Microsoft Word
Device & OS
macOS
Scenario
Pruning old custom document properties originally created using data from FileMaker Pro files, which require automated cleanup.
Observed behavior
AppleScript allows the creation and editing of custom document properties in Word but lacks a direct command to delete them, making a handoff to VBA necessary.
Before you start

Ensure that your version of Microsoft Word for Mac supports passing arguments via the 'run VB macro' AppleScript command, and verify that macros are enabled in your Word Security & Privacy preferences.

Solution 1Recommended

Pass the Variable Using the 'Run VB Macro' Command in AppleScript

Trigger a VBA macro from AppleScript and pass the custom property name as an argument to perform the deletion.

If your specific version of Microsoft Word for Mac supports argument passing from AppleScript, you can bridge the gap by sending the property name as a string directly to a receiving VBA macro.

1
Create the Receiving VBA Macro

Open the VBA Editor in Word (Option+F11) and create a subroutine that accepts a string argument. For example: `Sub DeleteCustomProperty(propertyName As String)`. Add error handling and the deletion command: `On Error Resume Next: ActiveDocument.CustomDocumentProperties(propertyName).Delete: On Error GoTo 0: End Sub`.

2
Write the AppleScript Trigger

In your AppleScript editor, construct the command to run the macro. Use a syntax similar to `tell application "Microsoft Word" to run VB macro macro name "DeleteCustomProperty" arg1 myVariableName`.

3
Execute the AppleScript

Run the AppleScript. It will pass the variable containing the custom document property name into the VBA environment, and Word will delete the corresponding property.

Pass the Variable Using the 'Run VB Macro' Command in AppleScript
AppleScript Limitations: Not all versions of Word for Mac perfectly handle passing arguments from AppleScript. If you encounter errors, consider shifting the entire property retrieval process into VBA.
Free Microsoft Office alternative

Try WPS Office for High-Performance Document Automation

If you frequently work with macros and need a lightweight, highly compatible alternative to Microsoft Word, consider WPS Office. It provides native support for VBA macros and seamlessly handles Microsoft Office formats without the heavy resource usage.

  1. 1. Download and Install WPS Office: Visit the official WPS website to download the free installer for your operating system.
  2. 2. Open Your Document: Launch WPS Writer and open your existing .docx file. The formatting and custom properties will be preserved.
  3. 3. Enable Macros: Access the Developer tab to enable macros and seamlessly execute your VBA scripts.
Free and lightweight office suite for macOS and WindowsHigh compatibility with Microsoft Word documents (.doc, .docx) and custom propertiesRobust built-in support for VBA macros and advanced document automationFamiliar user interface ensuring a seamless migration and minimal learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Why can't AppleScript delete custom document properties in Word?

Microsoft Word's AppleScript dictionary exposes commands to create and edit custom properties but intentionally omits a direct deletion command, making VBA the required tool for removal.

How do I enable macros in Microsoft Word for Mac?

Go to Word > Preferences > Security & Privacy, and select the option to enable all macros or to prompt you before enabling them.

Can I view my custom document properties without using code?

Yes, in Microsoft Word, you can go to File > Properties, and then navigate to the Custom tab to view, manually add, or manually delete custom document properties.