Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pause printing (XP)

    Is there a snippet of code that will pause the printer from printing?

    Thanks,
    John

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Pause printing (XP)

    I don't think there is anything in excel or VB to do it directly.

    I suppose that you could use sendkeys if you could figure out what keys to send and where to send them to.

    Steve

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Pause printing (XP)

    You need Windows API calls to do this. Copy the following code to a standard module.

    <img src=/w3timages/blueline.gif width=33% height=2>

    Private Enum PrinterAccessRights
    PRINTER_ACCESS_ADMINISTER = &H4
    PRINTER_ACCESS_USE = &H8
    PRINTER_ALL_ACCESS = &HF000C
    End Enum

    Public Enum Printer_Control_Commands
    PRINTER_CONTROL_PAUSE = 1
    PRINTER_CONTROL_RESUME = 2
    PRINTER_CONTROL_PURGE = 3
    PRINTER_CONTROL_SET_STATUS = 4
    End Enum

    Private Type PRINTER_DEFAULTS
    pDatatype As String
    pDevMode As Long
    DesiredAccess As Long
    End Type

    Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" _
    (ByVal pPrinterName As String, _
    phPrinter As Long, _
    pDefault As PRINTER_DEFAULTS) As Long

    Private Declare Function ClosePrinter Lib "winspool.drv" _
    (ByVal hPrinter As Long) As Long

    Private Declare Function SetPrinterApi Lib "winspool.drv" Alias "SetPrinterA" _
    (ByVal hPrinter As Long, _
    ByVal Level As Long, _
    buffer As Long, _
    ByVal Command As Long) As Long

    Public Sub PrinterCommand(ByVal DeviceName As String, ByVal cmd As Printer_Control_Commands)
    Dim lRet As Long
    Dim mhPrinter As Long
    Dim pDef As PRINTER_DEFAULTS

    ' Open the printer in admin. mode
    pDef.DesiredAccess = PRINTER_ALL_ACCESS
    lRet = OpenPrinter(DeviceName, mhPrinter, pDef)

    ' Send the command
    ' (both Level and Buffer are empty to send commands)
    lRet = SetPrinterApi(mhPrinter, 0, 0, cmd)

    ' Close the printer
    lRet = ClosePrinter(mhPrinter)
    End Sub

    <img src=/w3timages/blueline.gif width=33% height=2>

    Call it like this to pause a printer named "MyPrinter" (use the name as displayed in the File | Print... dialog):

    PrinterCommand "MyPrinter", PRINTER_CONTROL_PAUSE

    and like this to resume printing:

    PrinterCommand "MyPrinter", PRINTER_CONTROL_RESUME

Posting Permissions

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