VBA Printing Question

bcurrey

Board Regular
Joined
Aug 11, 2011
Messages
110
Office Version
  1. 365
Platform
  1. MacOS
I've searched on these forums and google and haven't been able to find anything I can get to work. I know this is pretty basic, but this is the first time I've tried printing from VBA to a network printer.

I have a report that runs automatically. A macro then runs to format it into the correct view. I want to print page 1 & 2 to the printer
\\fhu48g\FHU119P. This print is not my default printer.

Can someone tell me the code I need to use to do this? Thanks.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.




I tried that and kept getting errors. I also found the code below and tried it and get an error message. Any ideas? Thanks for the help, I'm much further along than I was yesterday!


The error code appears on the line I have highlighted in red. Error box reads "Run-time Error 1004. Method 'ActivePrinter of object'_Application' failed


Code:
Sub Macro1()
'
' Macro1 Macro
'
'
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "BCurrey"
    Range("B2").Select
        
Dim sCurrentPrinter As String
Const MyPrinter As String = "[URL="file://\\fhu48g\FHU119P"]\\fhu48g\FHU119P[/URL]"
sCurrentPrinter = Application.ActivePrinter
[COLOR=#ff0000][B]Application.ActivePrinter = MyPrinter
[/B][/COLOR]ActiveSheet.PrintOut '
Application.ActivePrinter = sCurrentPrinter
    
    
 End Sub
 
Upvote 0
When you look at Printer and Faxes in the control panel, the name under the printer icon IS the name of the printer. Try to copy and paste it between quotes.
 
Upvote 0
Thanks for the responses, I made some progress.
Using VBA code, I found the path to the printer. It is: "\\FHU48G\FHU119P on Ne03:"

I tried the new code below, and received the following error: "Run Time Error 424 - Object Required"

Code:
Sub Macro1()
'
' Macro1 Macro
'
'
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "BCurrey"
    Range("B2").Select
        
Dim sCurrentPrinter As String
Const MyPrinter As String = "[URL="file://\\FHU48G\FHU119P"]\\FHU48G\FHU119P[/URL] on Ne03:"
sCurrentPrinter = Application.ActivePrinter
[B][COLOR="#FF0000"]Application.ActivePrinter = MyPrinterActiveSheet.PrintOut '[/B][/COLOR]
Application.ActivePrinter = sCurrentPrinter
    
    
 End Sub.
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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