VBA print to parameterised printer

Sjun

New Member
Joined
Feb 17, 2010
Messages
3
Hi there,

I just registered on this forum, hoping someone can help me at the following issue;

I would like to have the ability to set a printername/number in cell A1, and use this cell as the name for the printer to where my printjobs get sent.

This way, I can set the printername, and use a button which activates a macro to print to a specific printer.

So far, I have this code, executed on buttonpress:
Code:
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
        "\\printserver\printer1 on Ne13:", Collate:=True

What I would like to have (but working) is:
Code:
ActivePrinter:=  "\\printserver\" & Worksheets("Sheet1").A1 
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Welcome to the Board.

Like this?

Application.ActivePrinter = "\\printserver\" & Worksheets("Sheet1").Range("A1").Value
 
Upvote 0
Welcome to the Board.

Like this?

Application.ActivePrinter = "\\printserver\" & Worksheets("Sheet1").Range("A1").Value
Hello Andrew, thank you for your help.

Although that looks like exactly what I want, it doesn't work. :(
I have also tried
Code:
Application.ActivePrinter = "\\printserver\" & ActiveSheet.Range("A1").Value
If I run the macro it says (translated from dutch)
error 1004 at runtime:
Method Activeprinter of object _Application failed.

I also tried to concatenate the string and cellvalue in a variable "MyPrinter" first, and then call
Code:
Application.ActivePrinter = MyPrinter

But that also fails.
 
Upvote 0
Finally, after trying lots of code, and with some help from this post, I managed to get it working: (y)
Code:
Dim MyPrinter As String
MyPrinter = ("\\printserver\" & Range("A1").Value)
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:=MyPrinter, Collate:=True

Thanks for pointing me in the right direction :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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