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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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: :beerchug:
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,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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