Option Explicit
Private Declare Function PrinterProperties Lib "winspool.drv" _
(ByVal hwnd As Long, ByVal hPrinter As Long) As Long
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 Type PRINTER_DEFAULTS
pDatatype As Long ' String
pDevMode As Long
pDesiredAccess As Long
End Type
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const PRINTER_ACCESS_ADMINISTER = &H4
Private Const PRINTER_ACCESS_USE = &H8
Private Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
Public Function DisplayPrinterProperties(DeviceName As String) _
As Boolean
'PURPOSE: Displays the property sheet for the printer
'Specified by Device Name
'PARAMETER: DeviceName: DeviceName of Printer to
'Display Properties of
'EXAMPLE USAGE: DisplayPrinterProperties Printer.DeviceName
'NOTES: As Written, you must put this function into a form
'module. To put into a .bas or .cls module, add a parameter for
'the form or the form's hwnd.
On Error GoTo ErrorHandler
Dim lAns As Long, hPrinter As Long
Dim typPD As PRINTER_DEFAULTS
typPD.pDatatype = 0
typPD.pDesiredAccess = PRINTER_ALL_ACCESS
typPD.pDevMode = 0
'DeviceName = Application.ActivePrinter
lAns = OpenPrinter(Printer.DeviceName, hPrinter, typPD)
If lAns <> 0 Then
lAns = PrinterProperties(Me.hwnd, hPrinter)
DisplayPrinterProperties = lAns <> 0
End If
ErrorHandler:
If hPrinter <> 0 Then ClosePrinter hPrinter
End Function