How to change default settings of active printer via vba

Posted on 2014-03-12
Last Modified: 2014-03-17

I have written the following code to print out timesheets.  However, the following code is not overwriting the printer defaults.

 ws.PageSetup.PaperSize = xlPaperLegal
  ws.PageSetup.BlackAndWhite = True

I'm thinking that I need the access the active printer and change the defaults there.
The activeprinter object does not seem to provide a way to access the above settings.  I've looked at the printout arguments, but there doesn't seem to be a way to change the paper size and black and white settings there.

Private Sub cmdPrintCompletedTimesheets_Click()
    ' Comments:
    ' Params  :
    ' Modified:
    On Error GoTo PROC_ERR
    Dim wb As Workbook
    Dim ws As Worksheet
    Set wb = ThisWorkbook
    For Each ws In wb.Worksheets
        If Left(ws.Name, 3) = "WTS" Then
            Application.EnableEvents = False
            ws.Range("C:C").EntireColumn.Hidden = False
            ws.Range("F:F").EntireColumn.Hidden = False
            ws.Range("I:I").EntireColumn.Hidden = False
            ws.Range("L:L").EntireColumn.Hidden = False
            ws.Range("O:O").EntireColumn.Hidden = False
            ws.Range("R:R").EntireColumn.Hidden = False
            ws.Range("U:U").EntireColumn.Hidden = False
            ws.Range("V:V").EntireColumn.Hidden = False
            ws.Range("W:W").EntireColumn.Hidden = False
            ws.Range("Z:Z").EntireColumn.Hidden = False
            ws.Range("AA:AA").EntireColumn.Hidden = False
            ws.Range("AB:AB").EntireColumn.Hidden = False
            ws.Range("AE:AE").EntireColumn.Hidden = False
            gblCheckBoxCalledFromCode = True
            wb.Worksheets(ws.Name).chkShowJobId.value = True
            gblCheckBoxCalledFromCode = True
            wb.Worksheets(ws.Name).chkShowCostCenter.value = True
            gblCheckBoxCalledFromCode = True
            wb.Worksheets(ws.Name).chkShowCostType.value = True
            gblCheckBoxCalledFromCode = True
            wb.Worksheets(ws.Name).chkShowDoubleTime.value = True
            gblCheckBoxCalledFromCode = True
            wb.Worksheets(ws.Name).chkShowWorkOrder.value = True
            gblCheckBoxCalledFromCode = True
            wb.Worksheets(ws.Name).chkShowLocation.value = True
            ws.PageSetup.PaperSize = xlPaperLegal
            ws.PageSetup.BlackAndWhite = True
        End If
    Application.EnableEvents = True
    Exit Sub
    MsgBox Err.Number & vbTab & Err.Description, vbCritical, "Sheet1.cmdPrintCompletedTimesheets_Click"
    Resume PROC_EXIT
End Sub

Open in new window

Question by:chtullu135
  • 3
  • 2
LVL 29

Expert Comment

ID: 39924019
Well when you use:

it will open the dialog box with all the printers and you have a button there Setup to choose for a specific printer what you want in term of paper etc... if you click on any printer it become the Activeprinter

so that this instruction:

After the previous one will return the printer you have selected. and this instruction:

ws.PrintOut will execute on the Activeprinter.


Author Comment

ID: 39924069
Hello gowflow,

I've reran the previous code and now it is working.  Go figure.
LVL 29

Expert Comment

ID: 39924176
ahhaaha one of those ... GOD KNOWS WHY !!! maybe when you first ran it it was selecting an other printer and somehow you did not notice so now maybe you paid attention and pressed on Setup that recorded the change ???

You know better.
LVL 29

Accepted Solution

gowflow earned 500 total points
ID: 39924182
OR ...

Probably you exited the routine somehow without going thru
Application.EnableEvents = True

and as it already went thru
Application.EnableEvents = False

when you ran the next time it did not do events hence did not register printer settings !!!

could be

Author Closing Comment

ID: 39934670
Thank, that was a good catch.

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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