ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   printing a print area to a non default printer (https://www.excelbanter.com/excel-programming/441325-printing-print-area-non-default-printer.html)

mikegibson[_3_]

printing a print area to a non default printer
 

Ive been printing to a select area to PDF, using a VBA code and setting
my default print to a program I have installed, CutePDF Writer, using
this code (pressing Ctrl+T):



VBA Code:
--------------------


Sub printmy()
curPrtArea = ActiveSheet.PageSetup.PrintArea
myPrtArea = "A47:H133"
ActiveSheet.PageSetup.PrintArea = myPrtArea
ActiveSheet.PrintOut
ActiveSheet.PageSetup.PrintArea = curPrtArea
'
' printmy Macro
' Macro recorded 4/3/2010 by Mike Gibson
'
' Keyboard Shortcut: Ctrl+t
'
End Sub

--------------------




However I want to change the default printer back to my normal printer
and im struggling to write the code to continue writing to CutePDF
Writer, (even though its not my default)



VBA Code:
--------------------


Sub printmy()
curPrtArea = ActiveSheet.PageSetup.PrintArea
myPrtArea = "A47:H133"
ActiveSheet.PageSetup.PrintArea = myPrtArea
ActiveSheet.PrintOut
ActiveSheet.PageSetup.PrintArea = curPrtArea
Dim Ptr As Printer
For Each Ptr In Printers
If Ptr.DeviceName = "CutePDF Writer" Then
Set Printer = Ptr
Exit For
End If
Next Ptr
'
' printmy Macro
' Macro recorded 4/3/2010 by Mike Gibson
'
' Keyboard Shortcut: Ctrl+t
'
End Sub
--------------------




Anyone have any ideas?

Happy Easter!!


--
mikegibson
------------------------------------------------------------------------
mikegibson's Profile: 805
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=192865

http://www.thecodecage.com/forumz


OssieMac

printing a print area to a non default printer
 
Hi Mike,

Try the following. Recording the code will give you the correct syntax and
printer name.

Turn on Macro recorder
In xl2007 select Microsoft button - Print - Print Select Printer etc.
In earlier versions of xl
Select File - Print

You should have the Printer Selection dialog box open.
Select the required printer. If the printer you want is already selected,
then select another one then re-select the required printer.
The Cancel button will change to Close
Click the Close button without printing
Stop macro recorder

You will record code something like the following.

Application.ActivePrinter = "Samsung CLP-310 Series on Ne00:"

If it was necessary to change from the already active printer and back again
you will see 2 lines of code.


--
Regards,

OssieMac


"mikegibson" wrote:


Ive been printing to a select area to PDF, using a VBA code and setting
my default print to a program I have installed, CutePDF Writer, using
this code (pressing Ctrl+T):




VBA Code:
--------------------



Sub printmy()
curPrtArea = ActiveSheet.PageSetup.PrintArea
myPrtArea = "A47:H133"
ActiveSheet.PageSetup.PrintArea = myPrtArea
ActiveSheet.PrintOut
ActiveSheet.PageSetup.PrintArea = curPrtArea
'
' printmy Macro
' Macro recorded 4/3/2010 by Mike Gibson
'
' Keyboard Shortcut: Ctrl+t
'
End Sub


--------------------




However I want to change the default printer back to my normal printer
and im struggling to write the code to continue writing to CutePDF
Writer, (even though its not my default)




VBA Code:
--------------------



Sub printmy()
curPrtArea = ActiveSheet.PageSetup.PrintArea
myPrtArea = "A47:H133"
ActiveSheet.PageSetup.PrintArea = myPrtArea
ActiveSheet.PrintOut
ActiveSheet.PageSetup.PrintArea = curPrtArea
Dim Ptr As Printer
For Each Ptr In Printers
If Ptr.DeviceName = "CutePDF Writer" Then
Set Printer = Ptr
Exit For
End If
Next Ptr
'
' printmy Macro
' Macro recorded 4/3/2010 by Mike Gibson
'
' Keyboard Shortcut: Ctrl+t
'
End Sub


--------------------




Anyone have any ideas?

Happy Easter!!


--
mikegibson
------------------------------------------------------------------------
mikegibson's Profile: 805
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=192865

http://www.thecodecage.com/forumz

.


mikegibson[_4_]

printing a print area to a non default printer
 

Thanks!

This is the final code, to print to a selected area to PDF, (using
CutePDF Writer, which is a free program), in one action (in this case,
Ctrl+T)



VBA Code:
--------------------


Sub printmy()
curPrtArea = ActiveSheet.PageSetup.PrintArea
myPrtArea = "A47:H133"
ActiveSheet.PageSetup.PrintArea = myPrtArea
ActiveSheet.PrintOut ActivePrinter:="CutePDF Writer"
ActiveSheet.PageSetup.PrintArea = curPrtArea
'
' printmy Macro
' Macro recorded 4/3/2010 by Mike Gibson
'
' Keyboard Shortcut: Ctrl+t
'
End Sub

--------------------




Thank you for your help.




OssieMac;690121 Wrote:

Hi Mike,

Try the following. Recording the code will give you the correct syntax

and
printer name.

Turn on Macro recorder
In xl2007 select Microsoft button - Print - Print Select Printer

etc.
In earlier versions of xl
Select File - Print

You should have the Printer Selection dialog box open.
Select the required printer. If the printer you want is already

selected,
then select another one then re-select the required printer.
The Cancel button will change to Close
Click the Close button without printing
Stop macro recorder

You will record code something like the following.

Application.ActivePrinter = "Samsung CLP-310 Series on Ne00:"

If it was necessary to change from the already active printer and back

again
you will see 2 lines of code.


--
Regards,

OssieMac


"mikegibson" wrote:


Ive been printing to a select area to PDF, using a VBA code and

setting
my default print to a program I have installed, CutePDF Writer,

using
this code (pressing Ctrl+T):




VBA Code:
--------------------



Sub printmy()
curPrtArea = ActiveSheet.PageSetup.PrintArea
myPrtArea = "A47:H133"
ActiveSheet.PageSetup.PrintArea = myPrtArea
ActiveSheet.PrintOut
ActiveSheet.PageSetup.PrintArea = curPrtArea
'
' printmy Macro
' Macro recorded 4/3/2010 by Mike Gibson
'
' Keyboard Shortcut: Ctrl+t
'
End Sub


--------------------




However I want to change the default printer back to my normal

printer
and im struggling to write the code to continue writing to CutePDF
Writer, (even though its not my default)




VBA Code:
--------------------



Sub printmy()
curPrtArea = ActiveSheet.PageSetup.PrintArea
myPrtArea = "A47:H133"
ActiveSheet.PageSetup.PrintArea = myPrtArea
ActiveSheet.PrintOut
ActiveSheet.PageSetup.PrintArea = curPrtArea
Dim Ptr As Printer
For Each Ptr In Printers
If Ptr.DeviceName = "CutePDF Writer" Then
Set Printer = Ptr
Exit For
End If
Next Ptr
'
' printmy Macro
' Macro recorded 4/3/2010 by Mike Gibson
'
' Keyboard Shortcut: Ctrl+t
'
End Sub


--------------------




Anyone have any ideas?

Happy Easter!!


--
mikegibson

------------------------------------------------------------------------
mikegibson's Profile: 805
View this thread: 'printing a print area to a non default printer -

The Code Cage Forums'
(http://www.thecodecage.com/forumz/sh...d.php?t=192865)

'Microsoft Office Help - Microsoft Office Discussion - Excel VBA

Programming - Access Programming' (http://www.thecodecage.com/forumz)

.



--
mikegibson
------------------------------------------------------------------------
mikegibson's Profile: 805
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=192865

http://www.thecodecage.com/forumz



All times are GMT +1. The time now is 07:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com