Solved

Word template - Change Paper source

Posted on 2006-06-22
4
317 Views
Last Modified: 2009-07-29
I need some VBA code that I can insert into a word template.

The code will detected which printer is my default and dependent on this it will change my page setup | paper source to letterhead using the ID for each printer.

If activeprinter=1809, 1802, 1801, 1704
then
firstpage = 1
otherpages = 1

else
firstpage = 2
otherpages = 2

Thanks
Priscilla
0
Comment
Question by:Priscilla_Hora
4 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 17021367
Something like this should get the job done.  Be sure to change the trays as desired.

Dim WithEvents wrdApp As Word.Application

Private Sub Document_Open()
    Set wrdApp = Application
End Sub

Private Sub wrdApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
    With Doc.PageSetup
        Select Case Trim(Left(wrdApp.ActivePrinter, InStr(wrdApp.ActivePrinter, " on ")))
            Case "Printer Name #1"
                .FirstPageTray = wdPrinterAutomaticSheetFeed
                .OtherPagesTray = wdPrinterMiddleBin
                Cancel = False
            Case "Printer Name #2"
                .FirstPageTray = wdPrinterAutomaticSheetFeed
                .OtherPagesTray = wdPrinterMiddleBin
                Cancel = False
            Case Else
                Cancel = True
        End Select
    End With
End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 71
Validating VB6 Function 19 56
VBA/SQL - Connect to SQL server and pull data 4 89
VB6 - Convert HH:MM into Decimal 8 53
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now