PDA

View Full Version : Help creating a macro that pauses and restarts



tammytutone
04-08-2008, 03:03 PM
Hello Everyone!

I am a soon to be ex-WordPerfect user and I created most of the macros and templates that my department uses. We also have Word 2003 on our computers but nobody uses it because they have just been using WordPerfect for so long. Now the company can no longer afford two office suites, so they're dumping WordPerfect. I want to recreate as many of our WordPerfect macros and templates, as I can, into Word macros and templates but I am stumped on a few. Here's a sample of a macro that is simple in WordPerfect but I can't figure out how to do it in Word VBA.

1. I would like to create a macro that puts a static text sentence into a document

2. Then it will pause so the user can add a name, which would be different every time

3. Then it will resume and add more static text

4. Lastly, it will pause again and either give the user a dropdown box with 2 or 3 selections or if that is not possible, just pause for the user to enter the text as in #2 above.

Since Word 2003 is new to me any suggestions and code samples are enormously appreciated. Thanks.

Tinbendr
04-08-2008, 07:25 PM
Here's a template I've put together. This gives a few examples of the options available.

Be sure to save the template in the Word template directory.

C:\Documents and Settings\%username%\Application Data\Microsoft\Templates

Open the template with File->New.

fumei
04-09-2008, 09:50 AM
Nice, Tindendr.

Although, it does not by any means require putting it into Words template folder.

"Be sure"

No. You can if you want to of course, but there is no "be sure" needed. I didn't, and looked at your result just fine.

I unzipped it to C:\ZZZ and double clicked it there. Executing a .dot file from any folder clones that .dot file to a new document.

tammytutone, you perhaps need to clarify what you mean exactly by "static text sentence". Static? As Tinbendr mentions, you can have text IN a template.

AutoText may very well be a viable route to use.

You can going to both have fun...and tear your hair out.

Word has a VERY different view/approach to what a document is, from WordPerfect. Microsoft's concept - the Object Model - of a document is radically different.

In your sample requirements, Tinbendr's approach is good.

Pausing execution of a macro for user input is NOT (generally speaking) a good idea, and for the most part not actually needed.

tammytutone
04-09-2008, 12:12 PM
Thank you Tinbendr and Fumei for the responses. The template is sort of what I want to do. I had created some forms with the text boxes and dropdowns, but the only problem is that this isn't going to be used as a template and I couldn't figure out how to insert the form(s) into a new document without the whole "document protect" issue.

What we do here in WordPerfect is generate a new document and one or many of the static text/text box/drop down combos are used in the document. All of these combos have language that never changes as well as some that can be modified and some choices that never change. In WordPerfect we call them conditions of probation and there's a set of about 20 conditions that I have users access by selecting them from a menu on the toolbar. They run pretty much like a keystroke macro with a couple of dialog boxes to enter or select variable information. When selected from the macro toolbar, the macro types in a couple of sentences that never change and then when it gets to the point where you want to put in how much time the person has to do, the macro launches a dialog text box for the user to manually type in the condition. They press OK and the macro continues typing a couple of more sentences that never change. Then on the last prompt, the macro stops again and there is a dialog dropdown box which has about 4 choices. The user selects one, presses ok and then the macro is complete. After that, the user has control of the rest of the document and continues typing whatever they want until they come to a different conditon.

I don't see how you can put that in a template. If there is a better way, I am open. I am going to see if I can accomplish some of this with Autotext, but I think I would have to lose the dropdown boxes if I go that route.

Any more thoughts?

Tinbendr
04-10-2008, 08:58 AM
You can accomplish the same things in Word, but they may be approached in a different manner.

You have a learning curve to over come and it seems you want a quick fix, but until you understand how Word works, Fumei and I (and others) will continue to offer 'pot shots' of suggestions to try an accomodate.

Can you provide a sample Word document?

In the places you want drop downs, maybe put those in bold, and list the possible options at the bottom on the document. Indicate where static text resides, and where users will be required to input addition text.

This sounds like a form. A set format with small changes from doc to doc. Sounds like a good place for a template.

David

tammytutone
04-10-2008, 11:19 AM
Thanks again for responding. You are spot on about the learning curve! I am having some difficulty wrapping my brain around how different these 2 programs are when it comes to templates, macros and forms! But anyway, I can give you a sample of the template that the user starts out with and a sample of the finished document if that helps. We run our templates and macros from a log in script, so if you want to see the template, you will have to lower your macro security. Again, I appreciate your help.

Tinbendr
04-17-2008, 11:24 AM
Ok,

Attached is a expansion of your example.

I've added a custom menu so you can easily pick the macro to run. (You can add this manually.)

I still think a template is the best way to approach this. Since bookmarks can be easily deleted by mistake, having a template gives you a fresh copy each time you start. With reopening a document, the chances increase for bookmark deletion.

Any approach you take will have pros and cons, but based on you example, this is how I would code it.

The userforms are rough, but i think you'll get the idea.

Post back if you have questions.

I hope this helps!