hi,
is it possible to create a macro that prints the active sheet with the following print conditions
1. print to "microsoft pdf" printer
2. pages 1-10 only
3. selected page size is FOLIO (8.5" x 13")
4. landscape
hi,
is it possible to create a macro that prints the active sheet with the following print conditions
1. print to "microsoft pdf" printer
2. pages 1-10 only
3. selected page size is FOLIO (8.5" x 13")
4. landscape
If you record a macro of you choosing those settings and printing it will get you most of the way. To get it to auto print to a specific printer adds a kink into it, though. With a function from here, I put this together and it seems to work.
You'll need to change the ".PaperSize" reference, since I don't have a Folio (8.5x13) option on my PC. Tabloid is 11x17. Also, if you try first by recording a macro, you'll see a plethora of additional PageSetup options you can change within VBA (margins, headers, etc.)
![]()
Sub Macro1() Dim prntr As String prntr = FindPrinter("Microsoft Print to PDF") Application.ActivePrinter = prntr Application.PrintCommunication = False With ActiveSheet.PageSetup .Orientation = xlLandscape .PaperSize = xlPaperTabloid End With Application.PrintCommunication = True ActiveWindow.SelectedSheets.PrintOut From:=1, To:=10, Copies:=1 End Sub Public Function FindPrinter(ByVal PrinterName As String) As String Dim Arr As Variant Dim Device As Variant Dim Devices As Variant Dim Printer As String Dim RegObj As Object Dim RegValue As String Const HKEY_CURRENT_USER = &H80000001 Set RegObj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") RegObj.enumvalues HKEY_CURRENT_USER, "Software\Microsoft\Windows NT\CurrentVersion\Devices", Devices, Arr For Each Device In Devices RegObj.getstringvalue HKEY_CURRENT_USER, "Software\Microsoft\Windows NT\CurrentVersion\Devices", Device, RegValue Printer = Device & " on " & Split(RegValue, ",")(1) If InStr(1, Printer, PrinterName, vbTextCompare) > 0 Then FindPrinter = Printer Exit Function End If Next End Function
hi,
thanks for the reply
got your idea to record macro, below works
cant find also 8.5 x 13 paper size so i just chose legal size
![]()
Sub PDFPRINTER() ' ' Macro1 Macro ' ' Dim prntr As String prntr = FindPrinter("Microsoft Print to PDF") Application.ActivePrinter = prntr Application.PrintCommunication = False With ActiveSheet.PageSetup .PrintTitleRows = "" .PrintTitleColumns = "" End With Application.PrintCommunication = True ActiveSheet.PageSetup.PrintArea = "" Application.PrintCommunication = False With ActiveSheet.PageSetup .Orientation = xlLandscape .PaperSize = xlPaperLegal End With Application.PrintCommunication = True ActiveWindow.SelectedSheets.PrintOut From:=1, To:=10, Copies:=1, Collate _ :=True, IgnorePrintAreas:=False End Sub Public Function FindPrinter(ByVal PrinterName As String) As String Dim Arr As Variant Dim Device As Variant Dim Devices As Variant Dim Printer As String Dim RegObj As Object Dim RegValue As String Const HKEY_CURRENT_USER = &H80000001 Set RegObj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") RegObj.enumvalues HKEY_CURRENT_USER, "Software\Microsoft\Windows NT\CurrentVersion\Devices", Devices, Arr For Each Device In Devices RegObj.getstringvalue HKEY_CURRENT_USER, "Software\Microsoft\Windows NT\CurrentVersion\Devices", Device, RegValue Printer = Device & " on " & Split(RegValue, ",")(1) If InStr(1, Printer, PrinterName, vbTextCompare) > 0 Then FindPrinter = Printer Exit Function End If Next End Function
Last edited by k1dr0ck; 09-28-2018 at 04:29 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks