Reputation: 103
I'm looking for a way to create a VBA script in MS Word that displays a list of predefined words. If the user clicks on one, it will be inserted into the document. Google searches only showed a way to create mailings with values from Excel but I want the words to be hard coded inside that VBA script (array maybe?) without any external files. Here is a small mockup how I imagined it:
Any ideas or tutorial links on how to achieve somehing like this? It doesn't have to look like the dialog in the image but have a collection of words in a dialog for the user to select.
Edit: It would be nice if the user would see a human readable label (like 'First name') but the inserted value would be a variable (like '$firstName').
Upvotes: 2
Views: 1173
Reputation: 3175
As it turns out, Greg Maxey has already built something very close to the requested utility by leveraging the native Building Blocks and AutoText features in Word. He calls his utility "Building Block Quick Pick" and the code for it is included in a free Word template add-in that contains a suite of Building Block utilities that he has created.
An article describing his Building Block utilities (with the Building Block Quick Pick detailed near the end) can be found here:
Gregory K. Maxey on Building Blocks & AutoText
The add-in can be downloaded from here:
Gregory K. Maxey's Building Block Enhanced Tools
The Building Block Quick Pick tool can be used as is or adopted to OP's exact format.
It's worth noting that one can also just create AutoText entries, place them in a template (for example, Building Blocks.dotx) and then place the Auto Text gallery on the QAT. This will provide a visual menu that with a single click will insert text at the insertion point. Here's what this would look like:
And here's a tutorial:
How to add AutoText from WikiHow
Upvotes: 0
Reputation: 3464
For creating the pop-up with a list of words, you can try something like this to connect a displayed value to the actual value.
As for the inserting into text part, this post seems to address the topic. Otherwise here's something from MSDN (http://support.microsoft.com/kb/212682/EN-US)
Upvotes: 1