MS Word - Creating complex document templates with macros

Hello Experts,

I have been tasked to convert seveveral complex WordPerfect macro enabled word processing documents to MS Word and am looking for document generation guidance and advice.
Right now I am seeking a hello world example for a ms word document that will open and prompt users with a multiple choice question and depending on answer will insert standard language/ sample text into the document.  I then need to understand how to add additional multiple choice prompts, loops, and so on.

If you can share a good resource to learn how to create complex macro templates like this I would really appreciate the help. My immediate interest is in ms 2007 but am also interested in 2010.  I do however need to avoid 3rd party docgen solutions.  Will I need to buy visual studio or are there no cost solutions to this common business need?

If you can share a brief step by step- hello world example I would appreciate even more.

Thanks again!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi MikeXna.

I would have enclosed an example, but EE does not allow the docm file extension.

The best way to do this, is to create a form, where the users make their choices with radiobutton etc. and then have an "OK" button in the end, which then get the values from the form, and does something after validation the user input, an example with a form containing 3 radiobuttons, put this code in the "OK"-buttons OnClick event:
Private Sub CommandButton1_Click()

If Me.OptionButton1.Value = True Then
    MsgBox ("First option chosen!")
ElseIf Me.OptionButton2.Value = True Then
    MsgBox ("Second option chosen!")
ElseIf Me.OptionButton3.Value = True Then
    MsgBox ("Third option chosen!")
End If

End Sub

Open in new window

Now depending on what the user has chosen, he will get a differen message.

In the Visual Studio editor, you the add this code into "ThisDocument":
Private Sub Document_Open()

End Sub

Open in new window

I hope this gets you a little bit closer to your goal.


Here is an example document that allows you to choose between several autotext entries and then places them in the document at a bookmark location. Hopefully it gives you an idea regarding getting started. Expert Exchange is a great resource for help as well as yahoo groups. Look especially for a Word_VBA group. (

The AutoText Entries are stored in the CustomBuildingBlocks.dotm file attached as well as the code to choose between them.

Dawn Bleuel
Word MVP
MikeXnaAuthor Commented:
Thanks Both!
Sorry for the delay in responding.
I like both of your suggestions and they have really got me thinking.  

I still could use some help putting 2 and 2 togehter.

I created a file called test.docm, turned on the develepment toolbar and added 3 radio button controls and a button.  I edited the code as you suggested and tested the form.  The message box worked as expected.  Thanks!

I copied your (renamed zip to dotm) to my Word startup folder.
I use XP so it was "C:\Documents and Settings\MyUserName\Application Data\Microsoft\Word\STARTUP"
I see the "Hello World"  autotext entries in Insert -> Text -> Quick Parts ->Building Blocks Organizer

Follow up questions:
What is the correct sytax to put in the Button Click Event to tell Word to put the "Hello Word" Autotext at a bookmark location in the document or open and place in different document?
What is the most elegant way to do this?  Do I maintain 2 documents?  One Form (MyForm.docm) with the questions/answers and another that has a semi formatted document  (MyDocument.docx) with bookmark locations?

Thanks Again!
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Take a look at the enclosed file (Remember to rename it).

I've written some comments in the OnClick event code of the OK button of the form.

Is this what you want?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MikeXnaAuthor Commented:
Thank you.  This is exactly what I needed to get started!
MikeXnaAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Office Suites-Other

From novice to tech pro — start learning today.