Re: creating envelope macro
- From: bryan <bryan@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 24 Nov 2008 11:16:04 -0800
Graham,
This did the trick.
Just got e-mail from user and works perfectly, no missing info.
I appreciate all your insight and help!
Bryan
"Graham Mayor" wrote:
A possibilty is that the print spooler is not responsing quickly enough to.
the command before it is dismissed. Try adding a line to turn off the Word
background printing option at the start of the macro and turn it back on
again when all is finished.
Options.PrintBackground = False
Ensure there is no 's' on Background as that is something else entirely. :)
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
bryan wrote:
Hi Graham,
The form once opened is pre-populating the formfields with data from
our host system.
I created a toolbar macro for the PrtEnv
My first inclination was user error as well but,
I was with the user once when she was showing me this and the
envelope doc opened briefly and was filled with data but, when
envelope inserted in printer - nothing printed.
Your thinking it might be he printer drivers?
If that could be the issue, what does one do?
Thanks,
Bryan
"Graham Mayor" wrote:
I always suppress a shudder when HP printer drivers are involved.
They make great hardware but their drivers leave a lot to be
desired. However printing three envelopes correctly out of four
suggests something else may be amiss - maybe pilot error ;)
I have tested it here and it works for me (albeit with a different
printer). How are you calling the macro? Could it be activated
before the user fills in the required fields that make up the
address?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
bryan wrote:
Good morning!
I have this envelope funtionality in production and it works great
except the user indicates that about every 3rd or 4th envelope
prints nothing. This is done from a template which populates from
our host system.
Once the user prints the form and envelope, there is another toolbar
macro which saves to our imaging system and then closes Word.
Here is code used to print envelope and form:
Sub PrtEnv()
'
' PrtEnv Macro
' Macro created 10/15/2008 by bjsorens
'
Dim sCurrentPrinter As String
sCurrentPrinter = ActivePrinter
ActivePrinter = "HP LaserJet 2100 Series PCL 6 on LPT1:"
Application.PrintOut FileName:=""
Dim sAddress As String
MsgBox "Insert envelope in printer", vbInformation, "Print Envelope"
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect Password:=""
End If
sAddress = .FormFields("Contact").Result & vbCr & _
.FormFields("Name1").Result & vbCr & _
.FormFields("Name2").Result & vbCr & _
.FormFields("Name3").Result
.Envelope.Insert ExtractAddress:=False,
OmitReturnAddress:= _ False, PrintBarCode:=False,
PrintFIMA:=False,
Height:=CentimetersToPoints _
(10.48), Width:=CentimetersToPoints(24.13),
Address:=sAddress, AddressFromLeft:=CentimetersToPoints(9.22), _
AddressFromTop:=CentimetersToPoints(3.73),
ReturnAddressFromLeft:= _
wdAutoPosition, ReturnAddressFromTop:=wdAutoPosition,
DefaultOrientation _
:=wdCenterLandscape, DefaultFaceUp:=True
.PrintOut Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="0"
.Sections(1).Range.Delete
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End With
ActivePrinter = sCurrentPrinter
End Sub
Thanks for your insight,
Bryan
"bryan" wrote:
Thanks again Graham.
Raving fan of the Discussion Group!
Bryan
"Graham Mayor" wrote:
The form is being printed by the line
Application.PrintOut FileName:=""
after you have declared the active printer.
The envelope is printed by the line
.PrintOut Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="0"
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
bryan wrote:
Hi Graham,
I did not notice this before from our network printer but,
I have printer 34 as my default.
I have a macro to print the envelope to printer 28 which works
but, it first print the form to printer 28 which I do not want.
The form will go to printer
34.
Here is my print envelope macro which should only print the
envelope to printer 28:
Sub PrtEnv()
'
' PrtEnv Macro
' Macro created 10/15/2008 by bjsorens
'
Dim sCurrentPrinter As String
sCurrentPrinter = ActivePrinter
ActivePrinter = "\\XS01\PRT28 on NE05:"
Application.PrintOut FileName:=""
Dim sAddress As String
MsgBox "Insert envelope in printer", vbInformation, "Print
Envelope" With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect Password:=""
End If
sAddress = .FormFields("InsuredName").Result & vbCr & _
.FormFields("Name2").Result & vbCr & _
.FormFields("Name3").Result & vbCr & _
.FormFields("Name4").Result
.Envelope.Insert ExtractAddress:=False,
OmitReturnAddress:= _ False, PrintBarCode:=False,
PrintFIMA:=False,
Height:=CentimetersToPoints _
(10.48), Width:=CentimetersToPoints(24.13),
Address:=sAddress, AddressFromLeft:=CentimetersToPoints(9.22), _
AddressFromTop:=CentimetersToPoints(3.73),
ReturnAddressFromLeft:= _
wdAutoPosition,
ReturnAddressFromTop:=wdAutoPosition, DefaultOrientation _
:=wdCenterLandscape, DefaultFaceUp:=True
.PrintOut Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="0"
.Sections(1).Range.Delete
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="" End With
ActivePrinter = sCurrentPrinter
End Sub
"Graham Mayor" wrote:
You shouldn't get the error message if you have altered the
template correctly and there is only one bookmark that needs to
be inserted into that envelope template and that is Bookmark1
which should be the only thing in the address frame. The
alternative method is probably simpler.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
bryan wrote:
Hi Graham,
I have this working using your Envelope #10.dot from your web
site. I had to remove the 2 macros from it and insert other
bookmarks and load those from the formfield. When I used 1
bookmark as your code suggest the information does not line up
on the envelope.
I got:
Name
DBA
address
CityStateZip
I do get a message after running the PrintEnvelope macro:
The margins of section 1 are set outside the printable area of
the page. Continue?
Is there a way to bypass this message or autoselect "Yes" ?
Thanks for all your help,
Bryan
"Graham Mayor" wrote:
There are a couple of ways to do this. If you are simply
distributing a form, and provided you can convince users to
run macros then you can unlock the form in code add an
envelope to the form and print that (#10) envelope
Dim sAddress As String
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect Password:=""
End If
sAddress = .FormFields("name").Result & vbCr & _
.FormFields("DBA").Result & vbCr & _
.FormFields("address").Result & vbCr & _
.FormFields("CityStateZip").Result
.Envelope.Insert ExtractAddress:=False,
OmitReturnAddress:= _
False, PrintBarCode:=False, PrintFIMA:=False,
Height:=CentimetersToPoints _
(10.48), Width:=CentimetersToPoints(24.13),
Address:=sAddress,
AddressFromLeft:=CentimetersToPoints(9.22), _
AddressFromTop:=CentimetersToPoints(3.73),
ReturnAddressFromLeft:= _ wdAutoPosition,
ReturnAddressFromTop:=wdAutoPosition, DefaultOrientation _
:=wdCenterLandscape, DefaultFaceUp:=True,
PrintEPostage:=False
.PrintOut Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="0"
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="" End With
If you are distributing the document as a template, then you
can additionally distribute an envelope template (you can
start with one of the envelope templates you can download
from my web site). Here I have called that envelope template
Form Envelope.dot and it should be installed in the user
templates folder along with the form template. The envelope
template has a bookmark Address1 in the address frame of the
template. (If you don't know how to modify the envelope
templates, e-mail me to the link on my web site and I will
send you a copy of the template I used for the macro)
Running the following macro will create a new envelope
document add the address, print it and close it without
saving. You can print as many envelopes as you wish without
affecting the form. The form is not unlocked in order to
create the new document.
This still has the problem of getting users to run macros and
an additional problem of two templates for the user to
install.
Dim sAddress As String
Dim dEnvelope As Document
With ActiveDocument
sAddress = .FormFields("name").Result & vbCr & _
.FormFields("DBA").Result & vbCr & _
.FormFields("address").Result & vbCr & _
.FormFields("CityStateZip").Result
Set dEnvelope =
Documents.Add(Options.DefaultFilePath(wdUserTemplatesPath) _
& "\Form Envelope.dot")
With dEnvelope
.Activate
With Selection
- References:
- Re: creating envelope macro
- From: bryan
- Re: creating envelope macro
- From: Graham Mayor
- Re: creating envelope macro
- From: bryan
- Re: creating envelope macro
- From: Graham Mayor
- Re: creating envelope macro
- Prev by Date: RE: How to copy header/footer from DocA to DocB
- Next by Date: RE: inserting section break - changing to landscape and then back
- Previous by thread: Re: creating envelope macro
- Next by thread: Using VBA to navigate within a document with existing hyperlinks
- Index(es):
Relevant Pages
|