[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to change default settings of active printer via vba

Posted on 2014-03-12
5
Medium Priority
?
796 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 31

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 31

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 31

Accepted Solution

by:
gowflow earned 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

656 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