Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Excel > Excel Programming

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 04-29-2019, 04:12 PM
hickeyt hickeyt is offline Windows 10 Office 2007
Novice
 
Join Date: Apr 2019
Posts: 5
hickeyt is on a distinguished road
Default Printer Listing

Is there a way in Excel VBA to create a listing of all of the printers available to that PC. In other words, I'd like to be able to loop through all of the printers that are available in Device Manager so that I can select one that is not the default printer based on some criteria that I could define and print to it instead
Reply With Quote
  #2  
Old 04-29-2019, 06:29 PM
Alansidman's Avatar
Alansidman Alansidman is offline Windows 10 Office 2019
Novice
 
Join Date: Apr 2019
Location: Steamboat Springs
Posts: 14
Alansidman is on a distinguished road
Default

https://docs.microsoft.com/en-us/off...alled-printers
Reply With Quote
  #3  
Old 04-30-2019, 07:10 AM
hickeyt hickeyt is offline Windows 10 Office 2007
Novice
 
Join Date: Apr 2019
Posts: 5
hickeyt is on a distinguished road
Default Thanks

Thanks.


My version of Excel does not support the Printers property of the Application Object so I get an error on
Dim prtLoop As Printer
and
Printers.Count

Is there some other way that would work with an previous version of Excel?
Reply With Quote
  #4  
Old 04-30-2019, 07:32 AM
Debaser's Avatar
Debaser Debaser is offline Windows 7 64bit Office 2010 32bit
Competent Performer
 
Join Date: Oct 2015
Posts: 165
Debaser is on a distinguished road
Default

No version of Excel supports a Printers property, but you can use WMI:

Code:
    Dim Printer As Object
    For Each Printer In GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2"). _
        ExecQuery("Select * from Win32_Printer")
    MsgBox Printer.Name
    Next
Reply With Quote
  #5  
Old 04-30-2019, 08:44 AM
hickeyt hickeyt is offline Windows 10 Office 2007
Novice
 
Join Date: Apr 2019
Posts: 5
hickeyt is on a distinguished road
Default Thanks

Works perfectly. Thanks for the help
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
listing johan-leroy Excel 1 11-26-2016 08:12 AM
Printer Problems-Need to reload printer each day jekronenfeld Windows 1 11-24-2014 12:35 AM
listing linked graphics eng1ne Drawing and Graphics 5 02-28-2012 06:42 AM
MS Word 2003, printer queue in 'printer properties' shows 1 job; no job in printer benhuxham Word 0 07-25-2011 06:58 PM
listing and counting words gencoglux Word 2 05-07-2010 05:10 PM


All times are GMT -7. The time now is 10:21 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft