Excel VBA Output to PDF Zoom % - excel

Is there a way to control the zoom % on the PDF when it is printed via a macro? I have zoomed in on the spreadsheet at 100% but the PDF always shows at 79.3% and it's really hard to see. If it is zoomed in at 200%, it shows perfectly fine on the PDF. I would normally ignore this aspect and just tell the user to zoom in but it's for the CEO and, ya know.
Here is what I have:
Private Sub CommandButton1_Click()
Dim Sel_Manager As String
'Specify headers to be repeated at the top
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = "$5:$10"
.PrintTitleColumns = "$B:$M"
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
'Manager selection through simple Inputbox
Sel_Manager = ComboBox1
'Insert autofilter for worksheet
Cells.Select
Selection.AutoFilter
'Select manager defined in inputbox
ActiveSheet.Range("B10", Range("M10").End(xlDown)).AutoFilter Field:=1, Criteria1:=Sel_Manager
ActiveSheet.Range("B10", Range("M10").End(xlDown)).AutoFilter Field:=2, Criteria1:="A"
'Select range to be printed and specify manager in filename
ActiveSheet.Range("B10", Range("M10").End(xlDown)).Select
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Sel_Manager + ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
ActiveSheet.ShowAllData
Application.PrintCommunication = True
End Sub

Before you end the sub, can you add those lines to your code please.
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.Zoom = False
'.PrintArea = Worksheets(ReportWsName).UsedRange
.FitToPagesWide = 1
'.FitToPagesTall = 1
End With
Application.PrintCommunication = True

Related

Convert excel columns towards different pdf pages

Below you can find my code that is working for a certain area. But I want to add a new element in the code but I can't find it how I can do it. The first area is A1:E42, but now I have one worksheet where I have 3 area. A1:E42, H1:K42 and O1:R42). How do I need to rewrite my code that the first area comes on the first pdf page, the second area on the second page et cetera.
Sub SavePDF()
Dim ws As Worksheet
Set ws = ThisWorkbook.ActiveSheet
With ws.PageSetup
.Orientation = xlLandscape
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
.PrintArea = "A1:E42"
End With
Set ws = Nothing
Sheets("Offerte_M").ExportAsFixedFormat x1TypePDF, Filename:= _
"C:\Intel\" & ActiveSheet.Range("F21").Value & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
MsgBox "Offerte has been saved as PDF. Press send now."
I thought maybe this was the correct way, but that doesn't work also.
Sub CommandButton1_Click()
Application.ScreenUpdating = False
Offerte_M.PageSetup.PrintArea = "A1:E42"
Offerte_M.PageSetup.PrintArea = "H1:K42"
Offerte_M.PageSetup.PrintArea = "O1:R42"
Worksheets(Array("Offerte_M")).Select.ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="C:\Intel\" & ActiveSheet.Range("F21").Value & ".pdf", _
OpenAfterPublish:=True
Offerte_M.PageSetup.PrintArea = ""
Offerte_M.PageSetup.PrintArea = ""
Offerte_M.PageSetup.PrintArea = ""
Offerte_M.Select
Application.ScreenUpdating = True
End Sub

Fill set columns to pdf

I am exporting a .xlsm sheet to PDF using Visual Basic (VBA).
I only want to export the columns A:Z.
I have tried this:
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
With ws.PageSetup
.PrintArea = "$A:$Z"
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
.Orientation = xlLandscape
.PaperSize = xlPaperA3
.RightMargin = Application.InchesToPoints(0.25)
End With
Next
ThisWorkbook.Sheets("Diagram").Select
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strFilename, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=True, _
OpenAfterPublish:=False
But I get space on the right side like it has filled the whole page just hid the columns I didn't select...
Is it any way to fix this problem and make column A:Z fill the whole page?
Any help is greatly appreciated :)

Print to pdf and fit rows on one page

The following code does not work correctly. I am attempting to print to pdf and fit all rows on one page. Any suggestions?
For Each sheet1 In ActiveWorkbook.Worksheets
With sheet1.PageSetup
.Orientation = xlLandscape
.Zoom = False
.FitToPagesTall = False
.FitToPagesWide = 1
End With
Next sheet1
worbook1.ExportAsFixedFormat Type:=xlTypePDF, Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False
In order to put your worksheet in one printable page you will need to make both FitToPagesTall and FitToPageWide equal to 1.
See below for the revised code:
For Each sheet1 In ActiveWorkbook.Worksheets
With sheet1.PageSetup
.Orientation = xlLandscape
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
End With
Next sheet1
worbook1.ExportAsFixedFormat Type:=xlTypePDF, Quality:=xlQualityStandard,_
IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False
I set both .FitToPagesTall = 1 and .FitToPagesWide = 1 and tried to execute it on a sample Excel file. It doesn't seem to work correctly. Below is the links to the Excel file and PDFs created when printed manually using Excel's 'Print-Fit all rows on one page' function and the one created by the VBA.
https://drive.google.com/file/d/1ohtP5VWz6_HnVVPYvcBnYlIciFKF3KlQ/view?usp=sharing
https://drive.google.com/file/d/1R0e8GBRFt9awFJgtD4VHhtV5ZVyUAA0s/view?usp=sharing
https://drive.google.com/file/d/1u851GmelwRX2_k1T5HgpFcQ1Hy2BLl4F/view?usp=sharing

VBA ExportAsFixedFormat to PDF for a range and changing display of output

I have the below code which outputs my desired range to a PDF files and correctly fits it to one portrait page:
With ActiveSheet.PageSetup
.Orientation = xlPortrait
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
rng.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=fSName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
However, on my PDF I have row letters on the left and an extra blank bar above my titles like so:
How can I get rid of these? I do not want them displayed and they have only appeared since I have added this section:
With ActiveSheet.PageSetup
.Orientation = xlPortrait
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
You need to set
ActiveSheet.PageSetup.PrintHeadings = False
to get rid of these column and row headings.
With ActiveSheet.PageSetup
.Orientation = xlPortrait
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintHeadings = False
End With

Dynamically Change File Name - ComboBox Excel Print

How can I have the name of the pdf dynamically changed based on Sel_Manager (combobox1) ? The viewers would like to print multiple PDFs and show them on the screen at the same time. Thank you in advance!
Private Sub CommandButton1_Click()
Dim Sel_Manager As String
'Specify headers to be repeated at the top
With ActiveSheet.PageSetup
.PrintTitleRows = "$5:$9"
.PrintTitleColumns = "$B:$M"
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
'Manager selection through simple Inputbox
Sel_Manager = ComboBox1
'Insert autofilter for worksheet
Cells.Select
Selection.AutoFilter
'Select manager defined in inputbox
ActiveSheet.Range("B14", Range("M14").End(xlDown)).AutoFilter Field:=1, Criteria1:=Sel_Manager
'Select range to be printed and specify manager in filename
ActiveSheet.Range("B14", Range("M14").End(xlDown)).Select
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"Manager.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
ActiveSheet.ShowAllData
End Sub
Answer found -
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Sel_Manager + ".pdf",

Resources