+ Reply to Thread
Results 1 to 2 of 2

Using VBA to control Duplex, Color Mode and Print Quality

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-02-2007
    Location
    Bryne, Norway
    MS-Off Ver
    Microsoft Office Excel 2010
    Posts
    230

    Using VBA to control Duplex, Color Mode and Print Quality

    Do any of you have a code I can use to control the printer from Excel? I probably need an API call together with some code. I have searched Internet and this forum, but can't find anything.

    MK - Norway

  2. #2
    Forum Contributor Tarball's Avatar
    Join Date
    04-21-2007
    Location
    Atlanta, GA
    Posts
    166
    From J. Walkenbach's Excel 2003 Power Programming. Great book. This will get you started. I have not fooled with the printer settings at all. This code is supposed to retreive the default printer information. Maybe play around with it and see if you can use it as a base for what you need?
    ActiveSheet.PageSetup.Orientation = xlLandscape
    Private Declare Function GetProfileStringA Lib "kernel32" _
                                               (ByVal lpAppName As String, ByVal lpKeyName As String, _
                                                ByVal lpDefault As String, ByVal lpReturnedString As _
                                                                           String, ByVal nSize As Long) As Long
    
    Sub DefaultPrinterInfo()
        Dim strLPT As String * 255
        Dim Result As String
    
        Call GetProfileStringA("Windows", "Device", "", strLPT, 254)
    
        Result = Application.Trim(strLPT)
        ResultLength = Len(Result)
    
        Comma1 = InStr(1, Result, ",", 1)
        Comma2 = InStr(Comma1 + 1, Result, ",", 1)
    
        'Gets printer’s name
        Printer = Left(Result, Comma1 - 1)
    
        'Gets driver
        Driver = Mid(Result, Comma1 + 1, Comma2 - Comma1 - 1)
        'Gets last part of device line
        Port = Right(Result, ResultLength - Comma2)
        'Build message
        Msg = "Printer:" & Chr(9) & Printer & Chr(13)
    
        Msg = Msg & "Driver:" & Chr(9) & Driver & Chr(13)
        Msg = Msg & "Port:" & Chr(9) & Port
        'Display message
        MsgBox Msg, vbInformation, "Default Printer Information"
    End Sub
    Last edited by Tarball; 11-02-2007 at 01:02 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1