Being able to select printer through VBA code!!??

olem

New Member
Joined
Oct 1, 2006
Messages
12
Well, I have managed to print sheets with vba code, but I use different printers (one black and white & on colour). The black and white printer is the standard printer (active), but sometimes I choose the color printer.
Menu bars are hidden in my dokument, and I have to use commandbuttons (macrocode) to print sheets.


How can I write a vba code who let me choose printer before I actually print the document?

Thx
Olem
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Erdinç E. Karaçam

Board Regular
Joined
Sep 23, 2006
Messages
202
Look at this codes.


Code:
Sub SelectPrinter()
        
    Dim No_0 As String
    Dim No_1 As String
    Dim SelectPrinter As String
    Dim Default_Printer As String
    
    Default_Printer = Application.ActivePrinter
    No_0 = "Ne00: üzerindeki Microsoft Office Document Image Writer "
    No_1 = "Ne01: üzerindeki HP LaserJet 1022 "
    
    Prompt = "For use " & No_0 & "please type No_0." + Chr(10)
    Prompt = Prompt + Chr(10) + "For use " & No_1 & "please type No_1."
    
    SelectPrinter = InputBox(Prompt, "PRINTER SELECTION", "No_0")
    
    If SelectPrinter = "No_0" Then
        SelectPrinter = "Ne00: üzerindeki Microsoft Office Document Image Writer "
    ElseIf SelectPrinter = "No_1" Then
        SelectPrinter = "Ne01: üzerindeki HP LaserJet 1022 "
    End If
    
    On Error Resume Next
    Application.ActivePrinter = SelectPrinter
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:=SelectPrinter, Collate:=True
    Application.ActivePrinter = Default_Printer
    
End Sub
 

olem

New Member
Joined
Oct 1, 2006
Messages
12
Thanks! Allmost, but it does not quite work for me. I get the standardprinter (active) whatever i choose. Even when I push cancel. I may have done something wrong. Q1: What do the term "üserindeki" do?
Q2: When I press "Cancel" it should cancel the printingjobb, is it possible

Best regards
OleM
 

Erdinç E. Karaçam

Board Regular
Joined
Sep 23, 2006
Messages
202
No_0 = "Ne00: üzerindeki Microsoft Office Document Image Writer "
No_1 = "Ne01: üzerindeki HP LaserJet 1022 "

These are the names of loaded printers in my laptop...
You should look at your printer names and change this rows.

Note:
"üzerinde" is a Turkish word, equals "on" in English.
 

Forum statistics

Threads
1,136,420
Messages
5,675,742
Members
419,585
Latest member
popsin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top