Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


openprinter fails in windows 10 64bit and office 64 bit

Posted on 2016-11-01
Medium Priority
Last Modified: 2016-11-01
i have been using the openprinter method to gather printer information just move over to office 64bit now the function fails.
Any solution
Private Type PRINTER_DEFAULTS: pDatatype As String: pDevMode As Long: DesiredAccess As Long: End Type
Private Declare PtrSafe Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long

   Dim pDefault As PRINTER_DEFAULTS: With pDefault: .pDatatype = vbNullString: .pDevMode = 0:  End With
res = OpenPrinter(Printer.DeviceName, mhPrinter, pDefault)
Question by:Svgmassive
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
  • 3
LVL 58
ID: 41868690
It would be best if you could avoid the 64 bit edition of office.  Microsoft itself is still recommending the 32bit version for most.

 If not, then the call will need to be changed and you'll need to use compiler constants and/or ptrsafe to execute the right code.  That's covered here:

Compatibility Between the 32-bit and 64-bit Versions of Office 2010

Read the section "Introducing the VBA 7 Code Base" to see how the compiler constants are used.

There is also a code inspector for 64 bit:

Microsoft Office Code Compatibility Inspector user's guide

 which you can use to run through your code and see what needs to be modified.

also, here are all the new 64 bit calls that were created:


and a list of all the calls that were modified for 64 bit:

Look in this to see if the call was modified.

LVL 58
ID: 41868790
By the way, I checked and your call is correct....in what way does the call fail?


Author Comment

ID: 41868827
its return zero and fails to open the printer
 res = OpenPrinter(Printer.DeviceName, mhPrinter, pDefault)
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

LVL 58

Accepted Solution

Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 41868882
Ah, sorry, didn't catch it first time around, the call is incorrect.   It's:

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

  phPrinter is LongPtr, not long


Author Comment

ID: 41868924
Jim i tried that but it still returns zero i am looking at the printer defaults

Author Comment

ID: 41869048
jim this works, I had to replace the pdefault with  ByVal 0&.

i am almost at the end of the routine,copymemory fails

#If VBA7 Then
Public mhPrinter As LongPtr
 Public Declare PtrSafe Function OpenPrinter Lib "winspool.drv" _
       Alias "OpenPrinterA" (ByVal pPrinterName As String, _
                             phPrn As LongPtr, pDefault As Any) As Long
Public mhPrinter As Long
 Public Declare PtrSafe Function OpenPrinter Lib "winspool.drv" _
       Alias "OpenPrinterA" (ByVal pPrinterName As String, _
                             phPrn As Long, pDefault As Any) As Long
#End If

res = OpenPrinter(Printer.DeviceName, mhPrinter, ByVal 0&)

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

596 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