Printing without margins

Fibo

New Member
Joined
Oct 22, 2023
Messages
18
Office Version
  1. 365
Platform
  1. Windows
"Hello, I need to convert a quotation currently in PowerPoint to an Excel format. The goal is to generate a PDF from Excel that matches the full-page, margin-free layout of our current PowerPoint PDFs. Despite trying various settings like 'fit to page' and setting margins to zero, I haven't been able to achieve this. Can you help me replicate this behavior in Excel?"
My full slides are always in A1:M25 on all my sheets.
The code bellow doesn't work. I still have white margins.
Sub PrintRangeToPDF()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")

' Set the print area
ws.PageSetup.PrintArea = "A1:O22"

' Adjust page setup
With ws.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = 0
.RightMargin = 0
.TopMargin = 0
.BottomMargin = 0
.HeaderMargin = 0
.FooterMargin = 0
.Orientation = xlLandscape
.PaperSize = xlPaperA4
End With

' Export to PDF
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\ExportedPDF_Dynamic.pdf"
End Sub
 
Have you tried manually printing (print selection) using the Microsoft Print to PDF printer? It should give narrower margins than Excel's ExportAsFixedFormat method, more in keeping with your page setup values. If so, this could be automated to call Excel's PrintOut method with a specific PDF printer instead of ExportAsFixedFormat.

The built-in Microsoft Print to PDF printer prompts for a .pdf output file name, but you can add another PDF printer which uses the same driver and 'prints' to a fixed .pdf output file instead of prompting. My code at Setting up a LOCAL printer does all the manual steps and adds a new PDF printer named "Print to PDF" which 'prints' to the file "C:\Temp\PrintToPDF.pdf" (the folder path must exist).

Your code would then print the range using ThisWorkbook.Worksheets("Sheet1").Range("A1:O22").PrintOut Copies:=1, ActivePrinter:=printer (where printer is the full printer name and network port of "Print to PDF") and copy "C:\Temp\PrintToPDF.pdf" to ThisWorkbook.Path & "\ExportedPDF_Dynamic.pdf".
 
Upvote 0

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