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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

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
Back
Top