Word Envelope printing macro - loop through document

I have a multiple page document with an Name and Address on every page or everyother page.
I need help on  a macro that will loop through the documet and use the MS Word built in Envelope feature and print envlopes for the addresses on every page.
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.

Eric FletcherCommented:
If your document is only addresses, you could just set the page dimensions for an envelope and print it all. Your return address could then be a header for every page.

If there is other content, is it easily distinguished from the address information? (by style, a code, format, etc.)
JElsterAuthor Commented:
The document  looks something like this..  It begins with the address... Can I add some code to distinguish the address and run a macro to create Envelopes.. thx

George Washington
1600 Penn Ave
Wash DC

Dear George


Eric FletcherCommented:
If the address lines can be uniquely identified, the task is a lot easier -- and you may be able to do it without a macro. by far the easiest and most effective way to identify structural elements is to apply styles.

For example, say the address lines use the style "address" and everything else has other styles. If you selected everything and set the font attribute to hidden, then used Find and Replace to change style=address to font=not hidden, then only the addresses would be visible. You could then print the document on envelope stock as I suggested above. You could record the procedure to make a simple macro to do this (and I would recommend you end it by closing the file without saving it so you retain your original formatting.

You could make it more sophisticated by just redefining styles, and of course you could write code to go through and build a new file of envelopes as you've asked. However, you will have to determine how repeatable this will be and how much effort you want to invest to do it.
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

JElsterAuthor Commented:
I need to print envelopes directly from the document - I don't need to modify or save the document...
just print envelopes from the document 'data'.   If I use styles on the address how can I grab all the address and print them using the envlope feature.. thanks again
Eric FletcherCommented:
Take a look at the two documents I have attached. One is a mockup of what I assume you have with the addresses set in a style called "address"; the other is a mockup to print on a #10 envelope. In it, the styles are defined slightly differently but with the same address style name.

To get all the addresses and print envelopes from the eeLetters.doc file, open the Find dialog (Ctrl-F). Click the More button so you can choose Format, Style=address for the Find what box. Click the checkbox to Highlight all items found in=Main Document. When you click Find All, just the address lines will be selected. Close the Find dialog and use Ctrl-C to copy. Now switch to the blank eeEnvelopes.doc document and paste (Ctrl-V). The copied addresses and the page breaks that precede each one will make an envelope for each of your letters. As you will see, I have set up a page header to contain a return address.

Note that I am assuming that your first address line includes the new page break (Ctrl-Enter) as in my eeLetters.doc example file. If not, you will need to modify the procedure a bit to be able to differentiate between the different addresses. Hopefully this will give you a start on it.


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
JElsterAuthor Commented:
How can I automate this into a single macro that I can place on the eeLetters.doc ?
How did you 'assign' the address area style?
Eric FletcherCommented:
Recording the steps doesn't record the "Find All" part, so you would have to tweak code to do it. Once the document is set up though, it is just a Find and a copy, so you may find it less complicated just to remember it (or make a note about how to do it).

A macro could certainly be written to do this for you, but I would question whether it would be worth the effort. If your requirement is more complex, you may need to consider writing code, but doing so for a single document seems like overkill.

To assign the style, just select the paragraph(s) and use the style pull-down to assign it. You can bring up the Styles and Formatting task bar with all the style names listed as well. To make it even easier, use a keyboard shortcut: once you have set the style once, press the F4 key to repeat the last action for all the rest.
JElsterAuthor Commented:
How do you set the styles on a range and view them.
I set one but it never finds it in my test. thx
Eric FletcherCommented:
Not sure I follow... Are you having trouble setting the style to paragraphs or in performing the Find?

In the eeLetters document, the addresses have been set with the "address" style, and if you use the Find dialog as I described, does it find all the instances as shown in the image below?

Note that I have set the style area width (in Tools Options, View dialog) to 0.65" to be able to see the style names applied to the paragraphs. As you can see, only the 12 paragraphs tagged with the address style have been found.
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
Microsoft Word

From novice to tech pro — start learning today.