Solved

How to change default settings of active printer via vba

Posted on 2014-03-12
5
763 Views
Last Modified: 2014-03-17
Hello,

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
    Application.Dialogs(xlDialogPrinterSetup).Show
    For Each ws In wb.Worksheets
        If Left(ws.Name, 3) = "WTS" Then
            Application.EnableEvents = False
            ws.Unprotect
            
            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
            ws.Protect
            ws.PrintOut
        End If
    Next
    
PROC_EXIT:
    Application.EnableEvents = True
    Exit Sub
    
PROC_ERR:
    MsgBox Err.Number & vbTab & Err.Description, vbCritical, "Sheet1.cmdPrintCompletedTimesheets_Click"
    Resume PROC_EXIT
    
End Sub

Open in new window

0
Comment
Question by:chtullu135
  • 3
  • 2
5 Comments
 
LVL 29

Expert Comment

by:gowflow
ID: 39924019
Well when you use:
Application.Dialogs(xlDialogPrinterSetup).Show

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:
Application.ActivePrinter

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

ws.PrintOut will execute on the Activeprinter.

gowflow
0
 

Author Comment

by:chtullu135
ID: 39924069
Hello gowflow,

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

Expert Comment

by:gowflow
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.
gowflow
0
 
LVL 29

Accepted Solution

by:
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
gowflow
0
 

Author Closing Comment

by:chtullu135
ID: 39934670
Thank, that was a good catch.
0

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

827 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