We've had great discussion, and I've learned a lot.
###Attached is the final macro that does it all:
[VBA] How to Set VBA Variable.scpt.zip (12.5 KB
Script is too long to post, so I'm just attaching a zip file, and posting the header comments. My thanks to @ccstone for his help as seen in this thread.
This script is just and example. it is NOT bullet-proof, and certainly needs more testing and error trapping before you use it in a production environment.
I have done some limited end-to-end testing, and it seems to work OK.
If you, or anyone, finds any issues, or has suggestions for improvement, please post here.
(*
====================================================
How to Set Word VBA Document Variable with AppleScript
====================================================
DATE: Tue, Dec 15, 2015
AUTHOR: JMichaelTX
PURPOSE:
• Run Word VBA Macro using Data from KM Variable(s)
PROCESS: This script performs the following steps:
1. Prompts User for VBA Macro Name
2. Prompts User for Word doc file to open
3. Prompts User for KM Variable to use
4. Opens the Word file
5. Gets the KM variable value
6. Sets (and creates if necessary) the Word Document Variable to the KM Variable value
7. Runs the VBA macro
CHANGES NEEDED:
• Move the code to create/set the Word doc variable into a function
• Add another Word variable that is the name of the KM var being set
• Revise the Word Macro to use this variable.
REF: KM Forum Topic
How to pass KM Variable into a Word Mac 2011 Macro (as a Variable)?
https://forum.keyboardmaestro.com/t/how-to-pass-km-variable-into-a-word-mac-2011-macro-as-a-variable/2582
====================================================
*)