View Single Post
  #21   Report Post  
Posted to microsoft.public.word.docmanagement
MoJR
 
Posts: n/a
Default Can I print an envelope without unlocking my document? Slight

Jay,
I believe I have the envelope situation under control. Thank you for that.
Printing a different number of copies for each page of the document I
mentioned has confounded me. I tried writing some code for that. I managed to
get the first couple of lines, but after that I was lost.
Thank yiou,
mojr

"MoJR" wrote:

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 Freedman" wrote:

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 FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

MoJR wrote:
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


"Jay Freedman" wrote:

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 FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.