none
Printing Envelope/Letter RRS feed

  • Question

  • I have this script which prints an envelope using form field info from document, it then prints the document.

    What I need this to do is print the envelope from manual feed and then print the document from tray1. 

    This info was presented as a solution awhile back for how to print an envelope. If I understood this better, I might be able to answer my own question!

    Sub Prt_Env_Ltr()
    '
    ' PrtEnv Macro
    ' Macro created 12/06/2009 by bjsorens
    '
    '


    Dim sCurrentPrinter As String
    sCurrentPrinter = ActivePrinter
    ActivePrinter = "\\XS01\PRT38PS on NE11:"

    Application.PrintOut FileName:=""

    Options.PrintBackground = False

    Dim sAddress As String
    MsgBox "Insert envelope in printer", vbInformation, "Print Envelope"
    With ActiveDocument
        If .ProtectionType <> wdNoProtection Then
            .Unprotect Password:=""
        End If
        sAddress = .FormFields("InsName").Result & vbCr & _
                    .FormFields("Addr").Result & vbCr & _
                    .FormFields("CSZ").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
    Options.PrintBackground = True

    'ActivePrinter = sCurrentPrinter
     
    End Sub

     

    Thanks in advance

    Thursday, December 16, 2010 12:56 PM

Answers

  • You skip read the page didn't you? ;)
    The page instructs to record a macro setting page setup in which you select the tray you want the document to print from ie the manual tray, which will give you the ID code for your particular printer. You can then use the ID code so produced in the macro e.g.

    Sub Prt_Env_Ltr()
    Dim sCurrentPrinter As String
    Dim sTray As String
    Dim sAddress As String
    'Record the current printer
    sCurrentPrinter = ActivePrinter
    'Record the current tray
    sTray = Options.DefaultTrayID
    ActivePrinter = "\\XS01\PRT38PS on NE11:"
    Application.PrintOut FileName:=""
    Options.PrintBackground = False
    MsgBox "Insert envelope in printer", vbInformation, "Print Envelope"
    With ActiveDocument
        If .ProtectionType <> wdNoProtection Then
            .Unprotect Password:=""
        End If
        sAddress = .FormFields("InsName").Result & vbCr & _
                    .FormFields("Addr").Result & vbCr & _
                    .FormFields("CSZ").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
     '********************************************
      'Set ID for manual printing
        Options.DefaultTrayID = 257 'Set the manual trayID option here
    '*********************************************
        .PrintOut Range:=wdPrintRangeOfPages, Item:= _
         wdPrintDocumentContent, Copies:=1, Pages:="0"
        .Sections(1).Range.Delete
        .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
    End With
    Options.DefaultTrayID = sTray
    ActivePrinter = sCurrentPrinter
    Options.PrintBackground = True
    End Sub



    <sorney> wrote in message news:6fe354e9-6e9c-4602-8dda-b24d4ba0b040@communitybridge.codeplex.com...

    Hi Graham,

    Looked at your site for printing.

    Question: From my code do set the ActivePrinter and tray to default prior to the Options.PrintBackground = True statement?

    Also, how do you get the try ID number. I see the macro, but not sure how one goes about getting the properties.

    Thanks..


    Graham Mayor - Word MVP
    www.gmayor.com
    Posted via the Communities Bridge
    http://communitybridge.codeplex.com/
    • Marked as answer by Bessie Zhao Monday, December 27, 2010 7:17 AM
    Thursday, December 16, 2010 3:02 PM

All replies

  • See http://www.gmayor.com/fax_from_word.htm which has sample code for switching trays at print time. It shows how to identify the tray IDs for your printer. All you then need to do is switch the tray after printing the envelope then print the rest of the document.


    Graham Mayor - Word MVP
    www.gmayor.com
    Posted via the Communities Bridge
    http://communitybridge.codeplex.com/
    Thursday, December 16, 2010 1:08 PM
  • Hi Graham,

    Looked at your site for printing.

    Question: From my code do set the ActivePrinter and tray to default prior to the Options.PrintBackground = True statement?

    Also, how do you get the try ID number. I see the macro, but not sure how one goes about getting the properties. 

    Thanks..

     

    Thursday, December 16, 2010 1:53 PM
  • You skip read the page didn't you? ;)
    The page instructs to record a macro setting page setup in which you select the tray you want the document to print from ie the manual tray, which will give you the ID code for your particular printer. You can then use the ID code so produced in the macro e.g.

    Sub Prt_Env_Ltr()
    Dim sCurrentPrinter As String
    Dim sTray As String
    Dim sAddress As String
    'Record the current printer
    sCurrentPrinter = ActivePrinter
    'Record the current tray
    sTray = Options.DefaultTrayID
    ActivePrinter = "\\XS01\PRT38PS on NE11:"
    Application.PrintOut FileName:=""
    Options.PrintBackground = False
    MsgBox "Insert envelope in printer", vbInformation, "Print Envelope"
    With ActiveDocument
        If .ProtectionType <> wdNoProtection Then
            .Unprotect Password:=""
        End If
        sAddress = .FormFields("InsName").Result & vbCr & _
                    .FormFields("Addr").Result & vbCr & _
                    .FormFields("CSZ").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
     '********************************************
      'Set ID for manual printing
        Options.DefaultTrayID = 257 'Set the manual trayID option here
    '*********************************************
        .PrintOut Range:=wdPrintRangeOfPages, Item:= _
         wdPrintDocumentContent, Copies:=1, Pages:="0"
        .Sections(1).Range.Delete
        .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
    End With
    Options.DefaultTrayID = sTray
    ActivePrinter = sCurrentPrinter
    Options.PrintBackground = True
    End Sub



    <sorney> wrote in message news:6fe354e9-6e9c-4602-8dda-b24d4ba0b040@communitybridge.codeplex.com...

    Hi Graham,

    Looked at your site for printing.

    Question: From my code do set the ActivePrinter and tray to default prior to the Options.PrintBackground = True statement?

    Also, how do you get the try ID number. I see the macro, but not sure how one goes about getting the properties.

    Thanks..


    Graham Mayor - Word MVP
    www.gmayor.com
    Posted via the Communities Bridge
    http://communitybridge.codeplex.com/
    • Marked as answer by Bessie Zhao Monday, December 27, 2010 7:17 AM
    Thursday, December 16, 2010 3:02 PM
  • Thanks Graham.

    I did read info in your site provided but, confused on the recording of macro.

    I was not sure how you were getting the macro listing :) 

     

    Appeciate your help!

    Thursday, December 16, 2010 3:17 PM
  • Works great!
    Quick question from testing.

    If I run the macro a 2nd time I get a blank envelope
    Why?

    Then sometimes users also get a message:
    "The margins of section 1 are set outside the printable area of the page.  Do you want to continue?"

    If yes, it prints fine - Is there a way to supress this message?


    Thanks, again.....

     


    Bryan Sorenson
    Friday, December 17, 2010 3:35 PM
  • I don't get the blank second envelope problem, but the two errors may be connected and are probably associated with your envelope address and envelope return styles. You may be able to suppress the error message with

        Application.DisplayAlerts = wdAlertsNone
        .PrintOut Range:=wdPrintRangeOfPages, Item:= _
         wdPrintDocumentContent, Copies:=1, Pages:="0"
        .Sections(1).Range.Delete
        Application.DisplayAlerts = wdAlertsAll

    but as I don't get the error, nor have your printer driver I cannot reproduce the problem.



    <sorney> wrote in message news:852e9f15-5150-43a1-8cce-9ff519137085@communitybridge.codeplex.com...

    Works great!
    Quick question from testing.

    If I run the macro a 2nd time I get a blank envelope
    Why?

    Then sometimes users also get a message:
    "The margins of section 1 are set outside the printable area of the page. Do you want to continue?"

    If yes, it prints fine - Is there a way to supress this message?


    Thanks, again.....




    --------------------------------------------------------------------------------
    Bryan Sorenson


    Graham Mayor - Word MVP
    www.gmayor.com
    Posted via the Communities Bridge
    http://communitybridge.codeplex.com/
    Saturday, December 18, 2010 10:50 AM
  • Will give it a try. Not a huge deal with the macro not printing when running again, only if envelpe jammed or something would they try that.

    Thanks again.....


    Bryan Sorenson
    Saturday, December 18, 2010 5:18 PM
  • Able to supress the message, however it does not print the envelope the second time. Like I mentioned not a big deal but, what do you mean that it could be associated with the envelope address and return styles?

     

    Thanks...

     


    Bryan Sorenson
    Monday, December 20, 2010 1:58 PM