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!
MikeXnaAsked:
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.

scifo_dkCommented:
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()
UserForm1.Show

End Sub

Open in new window


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

//Scifo_dk

0
dlc110161Commented:
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. (Word_VBA@yahoogroups.com)

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

Dawn Bleuel
Word MVP
CustomBuildingBlocks.zip
0
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.

@scifo_dk:  
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!

@dlc110161"
I copied your customBuildingBlocks.zip (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
Thanks!

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!
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

scifo_dkCommented:
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?

ins-bookmark.zip
0

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!
0
MikeXnaAuthor Commented:
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.