|
-
Dec 17th, 2007, 01:50 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] How to set printer through VB
I would like set the printer device through VB. How I can do that.
-
Dec 17th, 2007, 01:54 PM
#2
Re: How to set printer through VB
Printer.Devicename = "HP Laserjet"
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 17th, 2007, 02:09 PM
#3
Thread Starter
Frenzied Member
Re: How to set printer through VB
I want to show the printer dialog and then set the name in the textbox. Actually I don't want to print. I just to set only.
-
Dec 17th, 2007, 02:54 PM
#4
Thread Starter
Frenzied Member
Re: How to set printer through VB
I able to populate the printer devices into combo box. The problem is how I can set the printer devices as default?
Code:
Private Sub Form_Load()
'Add all the available printers to the combo box
For i% = 0 To Printers.Count - 1
Combo1.AddItem Printers(i%).DeviceName
Next i%
'Display the default printer
For i% = 0 To Combo1.ListCount - 1
If Combo1.List(i%) = Printer.DeviceName Then
Combo1.ListIndex = i%
Exit For
End If
Next i%
End Sub
-
Dec 17th, 2007, 03:48 PM
#5
Re: How to set printer through VB
in the combo click event
vb Code:
dim p as printer
for each p in printers
if p.devicename = combo1.text then set printer = p: exit for
next
note this does not change the windows default printer, it sets the printer your program will use
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 17th, 2007, 03:54 PM
#6
Thread Starter
Frenzied Member
Re: How to set printer through VB
Why it does't change the printer default in control panel?
-
Dec 17th, 2007, 09:41 PM
#7
Re: How to set printer through VB
because that is not what it does, if you want to change the windows default printer, you can use the SetDefaultPrinter api, do a search for that, in general you should change the default printer back, when you finish with it
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 17th, 2007, 09:48 PM
#8
Thread Starter
Frenzied Member
Re: How to set printer through VB
Nevermind, I will see it later. Let try your sample first. Let say I have chose the printer from combo list and want to use this printer for printing. How to print on paper using the selected printer?
I want to see how it works to print it on paper by the selected printer of choice and which printer name it will used to print the paper.
-
Dec 17th, 2007, 09:52 PM
#9
Re: How to set printer through VB
vb Code:
printer.print "this is a test" ' print something
printer.enddoc ' finish
set the printer you want to print to first
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|