Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to set the printer Properties?

Posted on 1998-09-25
Medium Priority
Last Modified: 2013-11-23
How can I set the printer properties I've selected in the commonDialog to the printer object?
 Eladio Rincón
Question by:eladio
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

Expert Comment

ID: 1436705
you should use the followin win32api. for it's detail refer to mircosoft's windows SDK document.
Declare Function SetPrinter Lib "winspool.drv" Alias "SetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Byte, ByVal Command As Long) As Long

/******** only part of the document, if you want do more, you should read more according to the 'see also' part at the end.
The SetPrinter function sets the state of the specified printer by pausing printing, resuming printing, or clearing all print jobs. The function can also be used to set printer data.

BOOL SetPrinter( HANDLE hPrinter,
 // handle of printer object
DWORD Level,
 // structure level
LPBYTE pPrinter,
 // address of array containing printer data
DWORD Command
 // printer-state command


Handle to the printer of interest.


Windows 95: Specifies the type of data contained in pPrinter. This parameter must be 0, 2, 3, 4, or 5. This parameter must be zero if Command is not equal to zero.

Windows NT: Specifies the type of data contained in pPrinter. This parameter must be 0, 2, 3, 5, or 6. This parameter must be zero if Command is not equal to zero.


This is either a DWORD value indicating the printer status, or a pointer to an array of bytes that may contain printer data.

If Level is 0, and the Command parameter is PRINTER_CONTROL_SET_STATUS, pPrinter must contain a DWORD value that specifies the new printer status to set. For a list of the possible status values, see the Status member of the PRINTER_INFO_2 structure. Note that PRINTER_STATUS_PAUSED and PRINTER_STATUS_PENDING_DELETION are not valid status values to set.

If Level is 0, but the Command parameter is not PRINTER_CONTROL_SET_STATUS, pPrinter must be NULL.

Windows 95: If Level is 2, 3, 4, or 5, pPrinter points to an array that contains PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_4, or PRINTER_INFO_5 structures, respectively.

Windows NT: If Level is 2, 3, 5, or 6, pPrinter points to an array that contains PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_5, or PRINTER_INFO_6 structures, respectively.


This parameter can be zero or one of the following values. If it is zero, the printer retains its original state and the printer data is reconfigured by using the structure to which pPrinter points. Value
 Pauses the printer.
 Deletes all print jobs in the printer.
 Resumes a paused printer.
 Sets the printer status.

If Command is any of the above values, Level must be zero.

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

You can obtain the handle hPrinter is by calling the OpenPrinter function.

To modify the current printer settings, an application should call GetPrinter to retrieve the current settings into a PRINTER_INFO_2 structure, modify the members of that structure as necessary, and then call the SetPrinter function.

The SetPrinter function ignores the following members of a PRINTER_INFO_2 structure:

pServerName, AveragePPM, Status, and cJobs

Pausing a printer suspends scheduling of all print jobs for that printer, except for the one print job that may be currently printing. Print jobs can be submitted to a paused printer, but no jobs will be scheduled to print on that printer until printing is resumed. If a printer is cleared, all print jobs for that printer are deleted, except for the current print job.

If the printer data structure contains a pointer to a security descriptor, only those components of the security descriptor that the caller has permission to write should be present. An application that wants to write particular security descriptor components must open the printer with sufficient access permission to modify those components. The following table shows the security descriptor components that can be modified for particular access permission values: Access Permission
 Modifiable Security Descriptor Components
 Owner, primary proup
 Discretionary access-control list (ACL)
 System ACL

If the calling application lacks a required permission, SetPrinter fails. Those components of a security descriptor that an application does not wish to modify should be NULL or not be present, as appropriate. If you do not want to modify the security descriptor, and are calling SetPrinter with a PRINTER_INFO_2 structure, set the pSecurityDescriptor member of that structure to NULL.

Windows 95: SetPrinter does not update the pShareName member in the PRINTER_INFO_2 structure.

Windows 95: SetPrinter is not supported when called against a Windows NT printer from a Windows 95 machine using the printer's UNC name.

See Also


Author Comment

ID: 1436706
I don't know if it's the right answer. Please send me and example, for example, changing the width, the height and the number of copies of the printer.


Accepted Solution

shogi earned 20 total points
ID: 1436707
You don't need to pass by API, just use the Printer Object

you can change the number of copies

Printer.Copies = xxx
Printer.PaperSize = vbConstanteForYourTypeOfPapierSize

Look in you help file to Printer Object, you will have all the information there.



Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

688 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