Can I print an envelope without unlocking my document? Slight retu

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
This question is mainly for Jay Freedman, but anyone may answer. That sounds
a bit snobby. Sorry! Anyway, Jay you helped me create a macro to unlock,
print an enveope and re-lock a document. That worked well because the address
was in one block and could be highlighted as a block. I have created a new
document and I want to run the same macro. However, the address is in two
blocks and cannot be highlighted as a single block without first unlocking
the document. This totally defeats the purpose of the document. It is an
automated document that uses the REF code to autopopulate the name in two
different pages of the document. To accomplish that I had to use one textbox
for the Name and one textbox for the Address. How do I accomplish this?
Thank you in advance!!
mojr
 
Hi =?Utf-8?B?TW9KUg==?=,
This question is mainly for Jay Freedman, but anyone may answer. That sounds
a bit snobby. Sorry! Anyway, Jay you helped me create a macro to unlock,
print an enveope and re-lock a document. That worked well because the address
was in one block and could be highlighted as a block. I have created a new
document and I want to run the same macro. However, the address is in two
blocks and cannot be highlighted as a single block without first unlocking
the document. This totally defeats the purpose of the document. It is an
automated document that uses the REF code to autopopulate the name in two
different pages of the document. To accomplish that I had to use one textbox
for the Name and one textbox for the Address. How do I accomplish this?
It might help if you copy the code Jay gave you into a message in this thread.
That way, we'd all (including Jay) have a starting point...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
 
MoJR said:
Hello,
This question is mainly for Jay Freedman, but anyone may answer. That
sounds a bit snobby. Sorry! Anyway, Jay you helped me create a macro
to unlock, print an enveope and re-lock a document. That worked well
because the address was in one block and could be highlighted as a
block. I have created a new document and I want to run the same
macro. However, the address is in two blocks and cannot be
highlighted as a single block without first unlocking the document.
This totally defeats the purpose of the document. It is an automated
document that uses the REF code to autopopulate the name in two
different pages of the document. To accomplish that I had to use one
textbox for the Name and one textbox for the Address. How do I
accomplish this? Thank you in advance!! mojr

Look in the Properties dialogs of the name and address form fields to find
out what their names are (the entry in the Bookmark box, which is the same
thing you use in the Ref fields to repeat the information). If they aren't
"Name" and "Address" then you'll have to change the names used in the
following updated macro:

Sub MakeEnvelope()
Dim addr As String
addr = _
ActiveDocument.FormFields("Name").Result & vbCr & _
ActiveDocument.FormFields("Address").Result

If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If


With Dialogs(wdDialogToolsEnvelopesAndLabels)
.DefaultTab = _
wdDialogToolsEnvelopesAndLabelsTabEnvelopes
.EnvReturn = Application.UserAddress
.AddrText = addr
.Show
End With


ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
Jay,
The new macro works great. I managed to modify it to include printing my
documents that go with the envelope. However, when I assign it to a
keystroke, it opens the print dialogue. If I then hit 'print' the delivery
address disappears and the envelope does not print, but two copies of the
document will print. When I assign it to a toolbar and click it with the
mouse it works fine. It would be nice to use the keyboard.
Thank you in advance for your help.
mojr
 
Jay,
The new macro works great. I managed to modify it to include printing my
documents that go with the envelope. However, when I assign it to a
keystroke, it opens the print dialogue. If I then hit 'print' the delivery
address disappears and the envelope does not print, but two copies of the
document will print. When I assign it to a toolbar and click it with the
mouse it works fine. It would be nice to use the keyboard.
Thank you in advance for your help.
mojr

I don't know of any (ordinary) way to make a macro behave differently
depending on whether it's launched from a button or a keystroke. It
takes some fairly sophisticated VBA to do that...

First, make absolutely sure that you've assigned the keystroke to the
macro (look in Tools > Customize > Keyboard and click the macro's name
to see what keystroke is assigned to it).

If that's OK, post your version of the code for me to look at. If I
don't see anything likely, I'll ask you to send me a copy of the
template.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
Jay,
This is the version of the code I developed.
Sub MakeEnvelope2()
Dim addr As String
addr = _
ActiveDocument.FormFields("name").Result
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If


With Dialogs(wdDialogToolsEnvelopesAndLabels)
.DefaultTab = _
wdDialogToolsEnvelopesAndLabelsTabEnvelopes
.EnvReturn = Application.UserAddress
.AddrText = addr
.Show
End With


ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
ActiveDocument.PrintOut
ActiveDocument.Close
End Sub

Thank you,
mojr
 
I don't see anything there that could cause the symptoms you described. (The
ActiveDocument.PrintOut statement should include the Background:=False
parameter to make the macro wait until spooling has finished before trying
to close the document, but that wouldn't change the behavior so
drastically.)

If you want me to look at the template and try to figure out what's wrong,
zip it and email it to me.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
Jay,
I guess I didn't put the Backgounf:=False statement in the right place.
Do I need to paste this code into an existing template for it to work as
expected? Currently, it is on a tool bar and not in any existing template.
mojr
 
Whoa, back up the truck... The macro and the toolbar must be stored in some
file, whether a document (.doc) or a template (.dot) file. What is that
file?
 
I think we're talking at cross purposes here...

When I mentioned the Background:=False parameter, what I meant was: In
the macro that you already have, which you posted in your message,
there's a line that says

ActiveDocument.PrintOut

You should edit that macro to change that line to

ActiveDocument.PrintOut Background:=False

But I don't expect that change to solve the problem about different
behavior from the toolbar button vs. the shortcut key. I have no
explanation for that problem. As I said before, if that problem
continues and it really bothers you, you can send me a copy of the
template that contains the macro and I'll look at it.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
Jay,
I assigned the macro to a hot key. When I press the hot key, the print
dialog comes up. Then, I either click the print button or press Alt+P and
everything works. Is this the way it should work? If it is, can we somehow
eliminate the step that I have to press the print button?
I also inserted the Background:=False parameter and it's working well.
Thank you.
mojr
 
Aha! The light just came on... When you wrote that the "print dialog
comes up", I thought you meant you saw the dialog for the File > Print
command. You really meant the Envelope dialog comes up.

Yes, that can be eliminated, but at a price. If you change the line

.Show

to

.Execute

then the envelope will added to the beginning of the document (as if
you had clicked the Add to Document button in the Envelope dialog)
without actually displaying the dialog. The ActiveDocument.Print
command in the macro will then print the whole document, which now
includes the envelope. (I hope your printer can automatically select
the envelope tray for the first "page" and the letter tray for the
remainder.)

The price is that the addition of the envelope will change the
document, so you'll be asked whether to save when the
ActiveDocument.Close statement runs. If you don't want that to happen,
then change the line from

ActiveDocument.Close

to

ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
Jay,
Thank you for your help. I will finalize this stuff tomorrow.
Now. I have a document that has 5 pages in it. Three of them are forms. I
need 1 copy of page 1. I need 2 copies of page 2 and I need 3 copies each of
pages 3 and 4 and 1 copy of page 5. I also would like to add 2 envelopes to
this document to be printed when I print the other pages. 1 envelope had a
return and a delivery address that are different. The second evnope uses the
return address for the delivery address as well.
What would be the best way to write "something" that I could use for this?
Is it possible to write it VBA should I try a different program or should I
leave you alone and go screaming into the night!?!?
I asked this question on one of the forums earlier in the week. I can't
remember which one and I haven't received a response on it.
Thank you again!!
mojr
mojr
 
Jay,
The code you sent in the last message didn't really change anything. When I
inserted ".Show to .Execute", I was asked to save the document as you stated.
When I inserted the "ActiveDocument.Close to ActiveDocument.Close
SaveChanges:=wdDoNotSaveChanges", and ran the code, the document printed as
you stated, BUT the original code does that now without changes.

This is the code I am currently using and made the above changes in;Sub
MakeEnvelope()
Dim addr As String
addr = _
ActiveDocument.FormFields("bs2nm").Result & vbCr & _
ActiveDocument.FormFields("bs2ag").Result

If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If


With Dialogs(wdDialogToolsEnvelopesAndLabels)
.DefaultTab = _
wdDialogToolsEnvelopesAndLabelsTabEnvelopes
.EnvReturn = Application.UserAddress
.AddrText = addr
.Show
End With


ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
ActiveDocument.PrintOut Background:=False


ActiveDocument.Close
End Sub

Currently, I use a combo key (not hot key, sorry) to run the macro. The
envelope dialog comes up, then I either click the 'print" command or press
Alt+P to actually print the document and envelope. I wan to eliminate the
step the second step if possible. I also need to run a second envelope with
that document that is a return envelope using the return address for delivery
and return.
Thank you,
mojr
 
Hi MoJR,

I don't make this stuff up -- I try it before I post it, and it works here
("here" being two separate computer/printer combinations, at home and at
work). I have to conclude that either you aren't following the instructions
correctly or you have some very different software installation.

When I modify the code as I described, and press the keyboard shortcut to
run the macro, it prints the envelope and the letter without showing any
dialogs or needing any other keys to be pressed. I believe that's the
behavior you're asking for.

Here's the code as I meant you to use it. If it does something other than
what I've described, please tell me *exactly* what happens in what order.

Sub MakeEnvelope()
Dim addr As String
addr = _
ActiveDocument.FormFields("bs2nm").Result & vbCr & _
ActiveDocument.FormFields("bs2ag").Result

If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If


With Dialogs(wdDialogToolsEnvelopesAndLabels)
.DefaultTab = _
wdDialogToolsEnvelopesAndLabelsTabEnvelopes
.EnvReturn = Application.UserAddress
.AddrText = addr
.Execute
End With


ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
ActiveDocument.PrintOut Background:=False


ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
Getting the extra page copies won't be too hard, although I don't have time
right now to play with it until it works right. The idea is that instead of
using the ActiveDocument.PrintOut method, you use the
Dialogs(wdDialogsFilePrint) dialog object -- similar to the way the macro
now uses the Dialogs(wdDialogToolsEnvelopesAndLabels) object -- and use its
Pages parameter to specify a list of the pages and their duplicate copies,
like this:

.Pages = "1,2,2,3,3,3,4,4,4,5"

Getting two envelopes might be a little trickier. The problem is that the
macro now acts as if you pressed the Add to Document button in the Envelopes
dialog, and then prints the envelope along with the rest of the document.
But Word allows only one envelope at a time to be attached to a document; if
you try to hand it another envelope, it will replace the one that's already
there. But if the return envelope always has the same address, then that can
be a separate and unchanging document stored in a file on your disk; the
macro can just open it, print it, and close it before or after dealing with
the main document.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
Jay,
I don't know why, but the code I copied into VBA just would not work. I
copied the new code you sent and it worked beautiflly. Obviously I did
something incorrectly.Thank you!!
mojr
 
Jay ,
The return envelope uses the same address each time. How do I make it a file?
Do I use the pages parameters on the same line as the (wdDialogsFilePrint)?
mojr
 
I mean that *separate from the macro* you make an ordinary Word
document, but with the page size set for the kind of envelope you use,
and with the address typed on the document as ordinary text. Save that
document somewhere convenient on your disk. Use the path and filename
of that document in the macro to open, print, and close it.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top