|
|
|
date: Tue, 14 Oct 2008 13:38:01 -0700,
group: microsoft.public.word.vba.general
back
Re: creating envelope macro
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
.GoTo What:=wdGoToBookmark, name:="Address1"
.TypeText sAddress
End With
.PrintOut
.Close wdDoNotSaveChanges
End With
End With
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
bryan wrote:
> I have a protected template which is populated with information from
> our host system: formfields Text1-Text4 have the name, DBA, address,
> CityStateZip.
>
> I want to create a macro to which these 4 are selected to print an
> envelope.
>
> I don't want the user to have to unprotect, highlight these, and then
> tools> Envelopes and Labels >etc, etc.
>
> Is there a way to programmically create a macro to print the envelope?
>
> Thanks,
> Bryan
date: Wed, 15 Oct 2008 10:41:02 +0300
author: Graham Mayor
Re: creating envelope macro
Hi Graham,
I am using the 1st macro and have that as a toolbar macro.
Works slick!
2 things:
1) I had to take out this piece of code, not sure what it's for?:
PrintEpostage:=False
** Compile Error - Named Argument not found **
2)How can I close the envelope as I do not want it to be part of the document?
Thanks again,
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
> .GoTo What:=wdGoToBookmark, name:="Address1"
> .TypeText sAddress
> End With
> .PrintOut
> .Close wdDoNotSaveChanges
> End With
> End With
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
> bryan wrote:
> > I have a protected template which is populated with information from
> > our host system: formfields Text1-Text4 have the name, DBA, address,
> > CityStateZip.
> >
> > I want to create a macro to which these 4 are selected to print an
> > envelope.
> >
> > I don't want the user to have to unprotect, highlight these, and then
> > tools> Envelopes and Labels >etc, etc.
> >
> > Is there a way to programmically create a macro to print the envelope?
> >
> > Thanks,
> > Bryan
>
>
>
date: Wed, 15 Oct 2008 05:34:11 -0700
author: bryan
Re: creating envelope macro
The epostage option may be language specific. There are probably other
entries there that you don't need also, but if it works leave them in as the
size of envelope is defined. The example below should work with the last
used envelope size. Which you use will be a compromise. You may also wish to
warn the users to insert an envelope into the printer as below.
Removal of the envelope is probably a good plan, so add the line
.Sections(1).Range.Delete
immediately before
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
eg
Dim sAddress As String
MsgBox "Insert envelope in printer", vbInformation, "Print Envelope"
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 Address:=sAddress
.PrintOut Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="0"
.Sections(1).Range.Delete
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End With
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
bryan wrote:
> Hi Graham,
> I am using the 1st macro and have that as a toolbar macro.
> Works slick!
> 2 things:
> 1) I had to take out this piece of code, not sure what it's for?:
> PrintEpostage:=False
> ** Compile Error - Named Argument not found **
>
> 2)How can I close the envelope as I do not want it to be part of the
> document?
>
> Thanks again,
> 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
>> .GoTo What:=wdGoToBookmark, name:="Address1"
>> .TypeText sAddress
>> End With
>> .PrintOut
>> .Close wdDoNotSaveChanges
>> End With
>> End With
>>
>> --
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor - Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> bryan wrote:
>>> I have a protected template which is populated with information from
>>> our host system: formfields Text1-Text4 have the name, DBA, address,
>>> CityStateZip.
>>>
>>> I want to create a macro to which these 4 are selected to print an
>>> envelope.
>>>
>>> I don't want the user to have to unprotect, highlight these, and
>>> then tools> Envelopes and Labels >etc, etc.
>>>
>>> Is there a way to programmically create a macro to print the
>>> envelope?
>>>
>>> Thanks,
>>> Bryan
date: Wed, 15 Oct 2008 16:33:05 +0300
author: Graham Mayor
Re: creating envelope macro
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
> .GoTo What:=wdGoToBookmark, name:="Address1"
> .TypeText sAddress
> End With
> .PrintOut
> .Close wdDoNotSaveChanges
> End With
> End With
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
> bryan wrote:
> > I have a protected template which is populated with information from
> > our host system: formfields Text1-Text4 have the name, DBA, address,
> > CityStateZip.
> >
> > I want to create a macro to which these 4 are selected to print an
> > envelope.
> >
> > I don't want the user to have to unprotect, highlight these, and then
> > tools> Envelopes and Labels >etc, etc.
> >
> > Is there a way to programmically create a macro to print the envelope?
> >
> > Thanks,
> > Bryan
>
>
>
date: Wed, 15 Oct 2008 10:39:01 -0700
author: bryan
Re: creating envelope macro
Quick question.
How can I have the envelope print to a specific printer without changing the
default printer?
Thanks,
Bryan
"Graham Mayor" wrote:
> The epostage option may be language specific. There are probably other
> entries there that you don't need also, but if it works leave them in as the
> size of envelope is defined. The example below should work with the last
> used envelope size. Which you use will be a compromise. You may also wish to
> warn the users to insert an envelope into the printer as below.
>
> Removal of the envelope is probably a good plan, so add the line
>
> .Sections(1).Range.Delete
> immediately before
> .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
>
> eg
>
> Dim sAddress As String
> MsgBox "Insert envelope in printer", vbInformation, "Print Envelope"
> 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 Address:=sAddress
> .PrintOut Range:=wdPrintRangeOfPages, Item:= _
> wdPrintDocumentContent, Copies:=1, Pages:="0"
> .Sections(1).Range.Delete
> .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
> End With
>
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
> bryan wrote:
> > Hi Graham,
> > I am using the 1st macro and have that as a toolbar macro.
> > Works slick!
> > 2 things:
> > 1) I had to take out this piece of code, not sure what it's for?:
> > PrintEpostage:=False
> > ** Compile Error - Named Argument not found **
> >
> > 2)How can I close the envelope as I do not want it to be part of the
> > document?
> >
> > Thanks again,
> > 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
> >> .GoTo What:=wdGoToBookmark, name:="Address1"
> >> .TypeText sAddress
> >> End With
> >> .PrintOut
> >> .Close wdDoNotSaveChanges
> >> End With
> >> End With
> >>
> >> --
> >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >> Graham Mayor - Word MVP
> >>
> >> My web site www.gmayor.com
> >> Word MVP web site http://word.mvps.org
> >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >>
> >>
> >> bryan wrote:
> >>> I have a protected template which is populated with information from
> >>> our host system: formfields Text1-Text4 have the name, DBA, address,
> >>> CityStateZip.
> >>>
> >>> I want to create a macro to which these 4 are selected to print an
> >>> envelope.
> >>>
> >>> I don't want the user to have to unprotect, highlight these, and
> >>> then tools> Envelopes and Labels >etc, etc.
> >>>
> >>> Is there a way to programmically create a macro to print the
> >>> envelope?
> >>>
> >>> Thanks,
> >>> Bryan
>
>
>
date: Wed, 15 Oct 2008 15:18:01 -0700
author: bryan
Re: creating envelope macro
Just add the extra lines of code (before and after printout) to switch the
printer. See http://www.gmayor.com/fax_from_word.htm for specific examples.
Are you going to know what printer your users have available?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
bryan wrote:
> Quick question.
> How can I have the envelope print to a specific printer without
> changing the default printer?
>
> Thanks,
> Bryan
>
> "Graham Mayor" wrote:
>
>> The epostage option may be language specific. There are probably
>> other entries there that you don't need also, but if it works leave
>> them in as the size of envelope is defined. The example below should
>> work with the last used envelope size. Which you use will be a
>> compromise. You may also wish to warn the users to insert an
>> envelope into the printer as below.
>>
>> Removal of the envelope is probably a good plan, so add the line
>>
>> .Sections(1).Range.Delete
>> immediately before
>> .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
>>
>> eg
>>
>> Dim sAddress As String
>> MsgBox "Insert envelope in printer", vbInformation, "Print Envelope"
>> 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 Address:=sAddress
>> .PrintOut Range:=wdPrintRangeOfPages, Item:= _
>> wdPrintDocumentContent, Copies:=1, Pages:="0"
>> .Sections(1).Range.Delete
>> .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
>> End With
>>
>>
>> --
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor - Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> bryan wrote:
>>> Hi Graham,
>>> I am using the 1st macro and have that as a toolbar macro.
>>> Works slick!
>>> 2 things:
>>> 1) I had to take out this piece of code, not sure what it's for?:
>>> PrintEpostage:=False
>>> ** Compile Error - Named Argument not found **
>>>
>>> 2)How can I close the envelope as I do not want it to be part of the
>>> document?
>>>
>>> Thanks again,
>>> 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
>>>> .GoTo What:=wdGoToBookmark, name:="Address1"
>>>> .TypeText sAddress
>>>> End With
>>>> .PrintOut
>>>> .Close wdDoNotSaveChanges
>>>> End With
>>>> End With
>>>>
>>>> --
>>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>>> Graham Mayor - Word MVP
>>>>
>>>> My web site www.gmayor.com
>>>> Word MVP web site http://word.mvps.org
>>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>>>
>>>>
>>>> bryan wrote:
>>>>> I have a protected template which is populated with information
>>>>> from our host system: formfields Text1-Text4 have the name, DBA,
>>>>> address, CityStateZip.
>>>>>
>>>>> I want to create a macro to which these 4 are selected to print an
>>>>> envelope.
>>>>>
>>>>> I don't want the user to have to unprotect, highlight these, and
>>>>> then tools> Envelopes and Labels >etc, etc.
>>>>>
>>>>> Is there a way to programmically create a macro to print the
>>>>> envelope?
>>>>>
>>>>> Thanks,
>>>>> Bryan
date: Thu, 16 Oct 2008 08:41:06 +0300
author: Graham Mayor
Re: creating envelope macro
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
>> .GoTo What:=wdGoToBookmark, name:="Address1"
>> .TypeText sAddress
>> End With
>> .PrintOut
>> .Close wdDoNotSaveChanges
>> End With
>> End With
>>
>> --
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor - Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> bryan wrote:
>>> I have a protected template which is populated with information from
>>> our host system: formfields Text1-Text4 have the name, DBA, address,
>>> CityStateZip.
>>>
>>> I want to create a macro to which these 4 are selected to print an
>>> envelope.
>>>
>>> I don't want the user to have to unprotect, highlight these, and
>>> then tools> Envelopes and Labels >etc, etc.
>>>
>>> Is there a way to programmically create a macro to print the
>>> envelope?
>>>
>>> Thanks,
>>> Bryan
date: Thu, 16 Oct 2008 08:44:20 +0300
author: Graham Mayor
Re: creating envelope macro
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
> >> .GoTo What:=wdGoToBookmark, name:="Address1"
> >> .TypeText sAddress
> >> End With
> >> .PrintOut
> >> .Close wdDoNotSaveChanges
> >> End With
> >> End With
> >>
> >> --
> >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >> Graham Mayor - Word MVP
> >>
> >> My web site www.gmayor.com
> >> Word MVP web site http://word.mvps.org
> >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >>
> >>
> >> bryan wrote:
> >>> I have a protected template which is populated with information from
> >>> our host system: formfields Text1-Text4 have the name, DBA, address,
> >>> CityStateZip.
> >>>
> >>> I want to create a macro to which these 4 are selected to print an
> >>> envelope.
> >>>
> >>> I don't want the user to have to unprotect, highlight these, and
> >>> then tools> Envelopes and Labels >etc, etc.
> >>>
> >>> Is there a way to programmically create a macro to print the
> >>> envelope?
> >>>
> >>> Thanks,
> >>> Bryan
>
>
>
date: Mon, 20 Oct 2008 09:02:01 -0700
author: bryan
Re: creating envelope macro
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
>>>> .GoTo What:=wdGoToBookmark, name:="Address1"
>>>> .TypeText sAddress
>>>> End With
>>>> .PrintOut
>>>> .Close wdDoNotSaveChanges
>>>> End With
>>>> End With
>>>>
>>>> --
>>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>>> Graham Mayor - Word MVP
>>>>
>>>> My web site www.gmayor.com
>>>> Word MVP web site http://word.mvps.org
>>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>>>
>>>>
>>>> bryan wrote:
>>>>> I have a protected template which is populated with information
>>>>> from our host system: formfields Text1-Text4 have the name, DBA,
>>>>> address, CityStateZip.
>>>>>
>>>>> I want to create a macro to which these 4 are selected to print an
>>>>> envelope.
>>>>>
>>>>> I don't want the user to have to unprotect, highlight these, and
>>>>> then tools> Envelopes and Labels >etc, etc.
>>>>>
>>>>> Is there a way to programmically create a macro to print the
>>>>> envelope?
>>>>>
>>>>> Thanks,
>>>>> Bryan
date: Tue, 21 Oct 2008 08:47:01 +0300
author: Graham Mayor
Re: creating envelope macro
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
> >>>> .GoTo What:=wdGoToBookmark, name:="Address1"
> >>>> .TypeText sAddress
> >>>> End With
> >>>> .PrintOut
> >>>> .Close wdDoNotSaveChanges
> >>>> End With
> >>>> End With
> >>>>
> >>>> --
> >>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >>>> Graham Mayor - Word MVP
> >>>>
> >>>> My web site www.gmayor.com
> >>>> Word MVP web site http://word.mvps.org
> >>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >>>>
> >>>>
> >>>> bryan wrote:
> >>>>> I have a protected template which is populated with information
> >>>>> from our host system: formfields Text1-Text4 have the name, DBA,
> >>>>> address, CityStateZip.
> >>>>>
> >>>>> I want to create a macro to which these 4 are selected to print an
> >>>>> envelope.
> >>>>>
> >>>>> I don't want the user to have to unprotect, highlight these, and
> >>>>> then tools> Envelopes and Labels >etc, etc.
> >>>>>
> >>>>> Is there a way to programmically create a macro to print the
> >>>>> envelope?
> >>>>>
> >>>>> Thanks,
> >>>>> Bryan
>
>
>
date: Tue, 21 Oct 2008 05:01:02 -0700
author: bryan
Re: creating envelope macro
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
> > >>>> .GoTo What:=wdGoToBookmark, name:="Address1"
> > >>>> .TypeText sAddress
> > >>>> End With
> > >>>> .PrintOut
> > >>>> .Close wdDoNotSaveChanges
> > >>>> End With
> > >>>> End With
> > >>>>
> > >>>> --
> > >>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> > >>>> Graham Mayor - Word MVP
> > >>>>
> > >>>> My web site www.gmayor.com
> > >>>> Word MVP web site http://word.mvps.org
> > >>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> > >>>>
> > >>>>
> > >>>> bryan wrote:
> > >>>>> I have a protected template which is populated with information
> > >>>>> from our host system: formfields Text1-Text4 have the name, DBA,
> > >>>>> address, CityStateZip.
> > >>>>>
> > >>>>> I want to create a macro to which these 4 are selected to print an
> > >>>>> envelope.
> > >>>>>
> > >>>>> I don't want the user to have to unprotect, highlight these, and
> > >>>>> then tools> Envelopes and Labels >etc, etc.
> > >>>>>
> > >>>>> Is there a way to programmically create a macro to print the
> > >>>>> envelope?
> > >>>>>
> > >>>>> Thanks,
> > >>>>> Bryan
> >
> >
> >
date: Fri, 14 Nov 2008 05:09:01 -0800
author: bryan
Re: creating envelope macro
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
>>>>>>> .GoTo What:=wdGoToBookmark, name:="Address1"
>>>>>>> .TypeText sAddress
>>>>>>> End With
>>>>>>> .PrintOut
>>>>>>> .Close wdDoNotSaveChanges
>>>>>>> End With
>>>>>>> End With
>>>>>>>
>>>>>>> --
>>>>>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>>>>>> Graham Mayor - Word MVP
>>>>>>>
>>>>>>> My web site www.gmayor.com
>>>>>>> Word MVP web site http://word.mvps.org
>>>>>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>>>>>>
>>>>>>>
>>>>>>> bryan wrote:
>>>>>>>> I have a protected template which is populated with information
>>>>>>>> from our host system: formfields Text1-Text4 have the name,
>>>>>>>> DBA, address, CityStateZip.
>>>>>>>>
>>>>>>>> I want to create a macro to which these 4 are selected to
>>>>>>>> print an envelope.
>>>>>>>>
>>>>>>>> I don't want the user to have to unprotect, highlight these,
>>>>>>>> and then tools> Envelopes and Labels >etc, etc.
>>>>>>>>
>>>>>>>> Is there a way to programmically create a macro to print the
>>>>>>>> envelope?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Bryan
date: Fri, 14 Nov 2008 16:08:27 +0200
author: Graham Mayor
Re: creating envelope macro
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 PrintEnvel |