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

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.


On Sat, 25 Feb 2006 17:10:27 -0800, "MoJR"
wrote:

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

"Jay Freedman" wrote:

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

On Fri, 24 Feb 2006 16:55:27 -0800, "MoJR"
wrote:

Jay,
As far as I know, the macro and toolbar are stored in the normal.dot template.
mojr

"Jay Freedman" wrote:

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?

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

"Jay Freedman" wrote:

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

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

"Jay Freedman" wrote:

On Thu, 23 Feb 2006 20:10:27 -0800, "MoJR"
wrote:

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