In the August issue of TechTrax, we gave you an article called Instant
Envelopes Using the MACROBUTTON Field and VBA, where you learned how to
add a MacroButton field to a master letter template, so users can double click
the MacroButton link to quickly capture address information from a letter to
print an envelope.
This month, we'll enhance that code. In this article, you'll
learn how to modify the MacroButton code to include an image. Then you'll learn how to
change the MacroButton click event so users only have to click once,
rather than double click.
We'll start with the field code. At this point, your template has a MACROBUTTON
field code inserted. When a user double clicks on the hidden text, which we have displayed, the MacroButton field causes a macro to run that captures the address contained in the address form field and copies it to the envelope dialog, then prints the envelope.
It's a good layout so far, but we're going to enhance it to make it slicker.
First, rather than displaying text, we'll display an image to represent the MacroButton field code. Granted, you'll
have to train your users to know to click the envelope image to print their
You'll need to capture an icon image to use. I'll be showing you how to capture
your image and modify it with the tools you already have within Windows. So
feel free to hunt out whatever icon you want. If you can get it displayed on
your screen, you can use it!
Capturing and Modifying an Image
Go hunt yourself down an image of an envelope. You can choose any image you
want, from the Internet or just use the envelope image within Office. When you
find the image you want, display it nicely on your screen and hit the PrintScreen
button on your keyboard. It may be abbreviated to something like PrntScrn.
But it's there somewhere! This button will take a picture of whatever
is on your screen. It won't seem like anything happened, but a picture of your
screen will now be sitting in your computer's temporary memory on the Clipboard.
Once the image is captured on the Clipboard, you need to modify it to save
out just the tiny envelope image. If you know how to cut and save out a portion
of an image, use your favorite photo editing program and go for it. If you don't
know how to handle this process, keep reading. I'll assume you don't have any
special photo program, so we'll just use Paint, which comes with Windows.
Click Start/Programs/Accessories/Paint to open Windows Paint
program. Click Edit/Paste or just hit Ctrl/V to paste the contents
of the Clipboard into Paint. The contents will be the snapshot you took of your
screen which contains the envelope image you're planning to use.
Below is an image of Paint, from my system, after I pasted in the snapshot
I took from Word showing the envelope icon.
Notice that there is a dotted line around the pasted image. When you paste
an image into Paint, it's automatically, already selected.
This next move is a little goofy. You see, you'll need to use the selection
tool (dotted square). However, also notice that the selection tool is already
activated. So first you need to deactivate it, then reactivate it so you can
use it to select the envelope image. When you deactivate it, it will release
the full image it now holds and free the tool to allow you to select another
portion of the image. Click on any other tool to release the
selection tool. After you do this, you can again click the Selection Tool
(the square, dotted icon on the left). Then click and drag a square
net around the envelope to select just this portion.
In the image above, you can see that I have a selection net drawn around
the envelope I plan to capture, or copy, from the full screen shot. Once the
item you want is selected, click Edit/Copy and then Edit/Paste,
or just hit Ctrl/C to copy and Ctrl/V paste.
A copy of your selected image will go back to the Clipboard when you copy it.
When you paste it, it will be dumped into the upper/left corner of the current
canvas (image). But look closely and you'll notice in the image below that the
pasted envelope is still selected, even though it now sits in the upper/left
corner of the other image. Leave it selected.
While still selected, you can save it off to a file by clicking Edit/Copy
If you were to click File/Save at this point, the entire file would
save. That's much more than you want. Even if you pasted the new image into
a blank canvas, it would still save the entire image canvas. Since you only
want the tiny envelope selection, you need to use the Edit/Copy To option.
But the problem with this option is that the only file format you can save the
image to is a BMP (bitmap). This format will work with Word, but it's a large
If you're just going to use this image in Word and you don't care that it could
be smaller in file size, then you're finished at this point. But if you were
planning to use this image on the web you'd want to add this last step. After
you've clicked Edit/Copy To and saved the image as a BMP, click File/Open
and retrieve the image again. If prompted to save the old screen shot that
would still be on the screen, say no.
Once the individual image is back on your screen, click File/Save As to
resave the same image, but under a new name. Click the drop down at the bottom
of the Save As dialog box and choose a smaller graphic file format, such
as JPG or GIF. Why you can't save it in this smaller format right
from the Copy To menu is something Microsoft will have to explain!
And now that you've done all that work capturing an envelope image for yourself,
I'll give you an even better one. Don't you hate it when instructors
do thatmake you work for nothing! But think of all that you've
Below is a nice little envelope graphic I created that you can feel free to
swipe. Just right click on the envelope image below and choose to save
the image to your own hard drive. But remember where you put it because you'll
need it again in a minute.
Modifying the MACROBUTTON Code
When we last left the letter template, it contained text which was displayed
as a double click macro hotspot. Now we'll pull a few tricks so you can use
the cute envelope image above.
Open your letter template. Click Insert/Picture/From File. Locate the
graphic you just saved and temporarily insert it anywhere into the template.
Select the image and make sure it still contains the Hidden attribute,
by either making sure there are dotted lines under it or by clicking Format/Font
and choose Hidden. But be sure you have hidden items set as viewable
in Tools/Options/View. You want to see the graphic on the page, but you
don't want it to print, so you convert it to hidden text. Also make sure you
still have hidden text turned off in the print dialog. See Tools/Options/Print
and make sure this option is not selected.
Before we can nest the image into the macro field code, it needs to
be tucked away in the template so it'll travel with the template when
you let others use it on their computers or via a network drive. Select the
image. Click Tool/AutoCorrect/AutoText. Don't use the Alt/F3 shortcut
this time, because you need to make sure the AutoText is properly placed in
the correct template. Enter a name for this item, such as envelope, and
click the Look in: dropdown at the bottom and select your letter template.
See the image below for dialog setting details.
Once the envelope image is safely tucked away in your template's AutoText,
you can delete it from the page. You'll have it displayed again in a minute,
but through field code.
Locate the old macro field code on your master template from the last lesson.
When you select the field code and hit Shift/F9 to convert the field
back into a code, it should look like the image below.
In the image above, you can see the field with field brackets, then the field
name, MACROBUTTON, then the name of the macro to be run, EnvelopePrint, and
finally the text that is displayed to the user. Move your cursor inside the
field code and start deleting the display text. Start at the first double quote
and delete to the end. The code should now only have the macro field name and
macro name, as shown below:
With your cursor located after the T in the word print, hit Ctrl/F9
to enter a new set of field brackets. These are not standard keyboard
brackets, these are special field brackets! Inside the new field brackets, type
AUTOTEXT and enter the name of the image you saved. I named mine envelope,
so that's what I type. The final code should look like the image below,
with the AUTOTEXT field code nested within the MACROBUTTON field code.
When you select the code and hit the F9 key to update the field to its
results, you should now see your envelope image back. The dots under the image
prove that it's still considered a hidden imageit will not print. Rather
than displaying text, the field now pulls the AutoText entry, which is your
Note! If you get an error stating that the image cannot span more
than one line, you had too much selected when you saved the image to AutoText.
Reselect just the image and resave it over the old AutoText file, then
update the field again.
Remember that you still need to have the template locked in just the first
section. See the previous
article if you don't remember all the original section and protecting
Give It a Test Run
You can now test out how the template works. Close the master template. Click
File/New and select the template to create a new document from it. Tab
to the address field and enter some information. Double click your envelope.
The text in the address field should be retrieved into your macro variable,
passed to the envelope dialog and an envelope will be printed in a second. You
won't see any of this going on, but if you've done everything correctly, your
printer will soon be flashingdemanding an envelope.
The Final Step
If you're feeling brave enough, there's one last, fairly quick step to finalize
your masterpiece. You just need to add a little quick code into the template
to change the macro button field code's default clicks from a double click to
one click. This isn't a necessary step. So if you're comfortable with two clicks,
consider your work here, done!
Reopen your master letter template by clicking File/Open and retrieve
it. Hit Alt/F11 to enter the VB editor (VBE). Be sure to select this
template from the project list in the VBE. You already have a module in it from
your first envelope macro. Double click to open that module.
Add the following code:
Sub AutoExec( )
Application.Options.ButtonFieldClicks = 1
Check the image below to make sure you've done it properly. The highlighted
code is the newly entered code.
Resave your template and make sure it's properly protected to activate the
field codes within it.
That's it! Now you can create a new letter from your master template, type
in your text and click the envelope image to instantly print an envelope.
Need more help getting your VBA code working right? Join our free VBA support
groups. See these links for details: http://groups.yahoo.com/group/Word_VBA/ and/or