Change the Printer in Visual Basic 6

The following snippet shows you how to change the current printer with Visual Basic 6 code.
Dim prt As Printer
For Each prt In Printers
  If prt.DeviceName = "MyPrinterName" Then
    Set Printer = prt
    Exit For
  End If

Where to Next?

Wonder where to go next? You can read existing comments below or you can post a comment yourself on this article .

Consider making a donation
Please consider making a donation using PayPal. Your donation helps me to pay the bills so I can keep running Imar.Spaanjaars.Com, providing fresh content as often as possible.

Feedback by Other Visitors of Imar.Spaanjaars.Com

On Saturday, May 26, 2007 6:45:44 AM harmohan said:

It is very good.

I am also interest in programing inVB. and need some help from you.
my problem is i have create a report in visual basic and it is ok. but i need some modificationa and i want this report take parameeter from a form like it take date from the form and show the report.

I hope you help me
On Saturday, May 26, 2007 9:39:55 AM Imar Spaanjaars said:
Hi harmohan,

I fail to see how this is related to the original topic of this article: changing the printer.

Please post these kind of questions on a forum like


On Wednesday, December 10, 2008 10:34:44 AM Nikhil said:
Dim prt As Printer
For Each prt In Printers
  If prt.DeviceName = "MyPrinterName" Then
    Set Printer = prt
    Exit For
  End If

this doesnt work. .....
On Wednesday, December 10, 2008 10:51:56 AM Imar Spaanjaars said:
Hi Nikhil,

Very constructive feedback and information. Typically results in an answer like:

Works for me...

On Wednesday, December 10, 2008 11:06:32 AM nikhil said:
even after writing this piece of code ... the printer is set as the default only ..

I am using shellexecute function to print an html page directly to a specified printer ....  
silent printing u see ...

so i wanted to specify printer name as a parameter ... and i used ur set printer buddy but doesnt work
On Wednesday, December 10, 2008 11:14:33 AM Imar Spaanjaars said:
May I suggest you post this on a forum like

There are people there who are better able to help you out with this.


On Wednesday, December 10, 2008 11:16:37 AM Nikhil said:
ok ... thank you ...
On Tuesday, December 23, 2008 11:40:39 PM Rich said:

Nikhil wrote to you asking you a question on the subject in your article and you say visit for answers?  Come on please.  If you write an article have the courtesy to help him out some more.  After all, you write the article.

On Wednesday, December 24, 2008 6:32:20 AM Imar Spaanjaars said:
Hi Rich,

Excuse me? Who are you to judge me on my time and efforts I have to make for this web site? First of all, why does writing an article mean I have to support it? Can you call the reporters of your news paper and ask for more background info on the articles they published? Can you call Stephan King and ask him about his intent of some of his characters? Where does it state that by viewing this article you get the right for support?

Secondly, Nikhil, didn't post very constructive feedback. I have only so many hours in a day, get tens to hundreds of messages from this site a day and have to choose wisely which ones I can answer in detail and which I can't.

Thirdly, Nikhil mentoned code not part of my article. He was also using stuff not explained in my article. As you can see, posting code and examples as comments is not the easiest thing to do. The P2P platform is designed for this. It's easier to post code, share uploads; in general: discuss non-functional code. If you did a little a homework, you'll notice I am the top poster on P2P and help where I can there. So, if Nikhil would have gone there for help and had posted his code, he would have found me, and as I said in my reply here, many others who could have helped him out.

Finally, I have posted over 1,600 comments here on my own web site helping out people who read my articles. Don't go tell me I am not supportive or responsive to my visitors.

So, why don't you go get a life and do something useful instead of making incorrect judgements on other people's web sites?

On Monday, May 4, 2009 1:31:14 PM MD said:
I'll be avoiding this site at all cost, a very poor judgment as well display of consideration for users by the host.   Seeing his/her main viewers to the site are people looking for "help", laziness and ignorance towards them does not help your site out at all.  I really frown upon this act of immaturity.
On Monday, May 4, 2009 2:43:53 PM Imar Spaanjaars said:
Hi MD,

"laziness and ignorance"? Oh, come on. Do some research before you make a judgement. Take a look here:

or here:

and you'll see how supportive I am towards readers of my articles if they ask sensible questions. Try that, and judge again. Posting an article does not mean I have to reply to every question I get; especially not if they are not related to the original article. Calling that laziness is misjudgement, IMHO....

I simply cannot help everybody with every query on this site; some topics are better suited for more general programming forums. If you don't understand that, I guess you don't have a site like this yourself so you don't understand how this works and what work is involved.

Then again. you'll be avoiding this site at all cost, so you probably won't see this reply.

Anyway, suit yourself. The back button is only one click away.... ;-)

On Monday, July 20, 2009 6:13:07 AM Anon said:
Hey Imar, just wanted to say, this site is great, sorry you have to deal with so-and-sos like them, no neeed to reply, i wont be checking this thread again.

On Thursday, September 2, 2010 5:31:31 PM VB6Faithful said:
Hi Imar,
The code works great. I think nikhil needed to look at automation if he wants to print from a specific program. If he wanted to print from a textbox on a Form, the following would work:
Private Sub Command1_Click()
Dim prt As Printer
For Each prt In Printers
  If prt.DeviceName = "doPDF v7" Then
    Set Printer = prt
    Exit For
  End If
Printer.Print Text1.Text
End Sub

Actually setting the default printer is very cumbersome
On Tuesday, September 27, 2011 7:46:57 AM gil said:

do you use  a database or?? if you use database  what kind of database  you use?? access or mysql?????
On Tuesday, September 27, 2011 11:24:20 AM Imar Spaanjaars said:
Use a database to change a printer? No, I don't. Do you? ;-)

On Friday, January 20, 2012 7:03:17 AM thilak said:
dear all
how can i select printer folder true Vb cording
On Sunday, April 1, 2012 4:40:20 AM Pixie said:
Just browsing - had a look at the site content.

Absolute crap. Give it away Imar you havent got the temprement required.

On Sunday, April 1, 2012 7:14:32 AM Imar Spaanjaars said:
What a very constructive piece of feedback......

On Wednesday, March 26, 2014 11:03:14 PM B said:
Does this piece of code change/set the default printer? Or uses the printer listed for the current print job?
On Thursday, March 27, 2014 9:03:08 AM Imar Spaanjaars said:
It just changes the printer for the current job.


On Thursday, March 27, 2014 5:05:34 PM B said:
Thanks for your prompt response.
On Tuesday, May 13, 2014 1:54:08 AM dd said:
I think this is great!
I think a lot of my responses would've been a lot more sarcastic, your doing a good job.
The information I found here gave me what I needed and a chuckle as well.
Conclusion: some people take themselves too seriously, lighten up
On Saturday, July 22, 2017 4:31:00 AM antony said:

i have various vb datareport...but printing time only defalut printer i can change default printer as my wish?  
papersize code not work in datareport

On Friday, August 4, 2017 8:59:16 PM Imar Spaanjaars said:
Are you still using VB6? If not, you picked the wrong post to ask this question ;-)


On Thursday, October 19, 2017 9:56:14 PM walt said:
LOL...I read the old comments. Some people are just worthless forms of carbon and water. I had a programming blog years ago that I had to shut down because of all the questions.
On Thursday, August 16, 2018 11:59:48 AM Sam Soloman said:
I wrote this few lines and thought it would work, but it does not.

    If Printer.DeviceName <> "Win2PDF" Then
        MsgBox "we see " + Printer.DeviceName + "  and will try to change it"
        Printer.DeviceName "Win2PDF"
    End If
I searched the data bank and found several examples to set the printer for different printer properties or from inside Cristal Reports.
Learn more at

Talk Back! Comment on Imar.Spaanjaars.Com

I am interested in what you have to say about this article. Feel free to post any comments, remarks or questions you may have about this article. The Talk Back feature is not meant for technical questions that are not directly related to this article. So, a post like "Hey, can you tell me how I can upload files to a MySQL database in PHP?" is likely to be removed. Also spam and unrealistic job offers will be deleted immediately.

When you post a comment, you have to provide your name and the comment. Your e-mail address is optional and you only need to provide it if you want me to contact you. It will not be displayed along with your comment. I got sick and tired of the comment spam I was receiving, so I have protected this page with a simple calculation exercise. This means that if you want to leave a comment, you'll need to complete the calculation before you hit the Post Comment button.

If you want to object to a comment made by another visitor, be sure to contact me and I'll look into it ASAP. Don't forget to mention the page link, or the QuickDocId of the document.

For more information about the Talk Back feature, check out this news item.