How can I pdf multiple sheets in my Workbook into one pdf in landscape format? Here is what I have. I am missing the landscape syntax -
Sub CompileReport()
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="F:\Report\Test" & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
End Sub
Thanks!
Try this one:
Sub CompileReport()
Dim mySheets As Variant, sh
mySheets = Array("Sheet1", "Sheet2", "Sheet3")
For Each sh In mySheets
Sheets(sh).PageSetup.Orientation = xlLandscape
Next
Sheets(mySheets).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="F:\Report\Test" & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
End Sub
Related
I have the below code, and I am here to ask what I would need to add to the code to print pages 1 to 3 only?
Sub PrintVisa()
Dim invoiceRng As Range
Dim pdfile As String
'Setting range to be printed
Set invoiceRng = Range("C7:L175")
pdfile = " Seabourn_Visa_Letter"
invoiceRng.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=pdfile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=True, _
OpenAfterPublish:=True
Please, try the next code:
Sub ExportFirstThreeSheets()
Dim FileName As String
FileName = ThisWorkbook.Path & "\MyThreeSheets.pdf"
Sheets(Array(1, 2, 3)).copy 'it creates a new workbook containing the first three sheets
With ActiveWorkbook
.ExportAsFixedFormat xlTypePDF, FileName, , , , , , True
.Close False
End With
End Sub
The ExportAsFixedFormat has a page range built in. See below:
Sheet5.ExportAsFixedFormat Type:=xlTypePDF, Filename:="YouFileName.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, From:=1, To:=3, OpenAfterPublish:=True
I have the below script to export each excel sheet to a separate PDF page. It works fine, except for one small issue. I need the range Columns A:H to fit on one PDF page. How can I update the below script to make sure I export all information on one page for the specified columns?
Sub ExportToPDFs()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Select
nm = ws.Name
ActiveSheet.Columns("A:H").ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\My Folder\" & nm & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
Next ws
End Sub
I would set the print area to A:H and set scale to fit to 1 page wide and 1 page high through the Page Setup part of the Ribbon. Then the following code should work without having to mess with the scaling through VBA.
Sub ExportToPDFs()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Select
nm = ws.Name
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\My Folder\" & nm & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
Next ws
End Sub
i have the following vba codes
Sub SaveAsPDF()
Dim FileAndLocation As Variant
Dim strPathLocation As String
Dim strFilename As String
Dim strPathFile As String
strPathLocation = Worksheets("Sheet1").Range("A2").Value
strFilename = Worksheets("Sheet1").Range("A4").Value
strPathFile = strPathLocation & strFilename
Sheets("Sheet2").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
strPathLocation & strFilename & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
End Sub
what i want to achieve is to save Sheet2 as pdf to the specified path and specified file name
Try that.
Select in vba your sheet and use this function to export, the filename you could pass as a parameter in the function.
Sub ExportarPDF()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="yourpath.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
I have this macro that saves to a defined path which is not useful since multiple people will be using the file.
Sub SavetoPdf()
'
' SavetoPdf Macro
' To Save to PDF Details
'
' Keyboard Shortcut: Ctrl+s
'
Range("E31:I54").Select
Application.CutCopyMode = False
ChDir "/Users/Me/Desktop/"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
"/Users/Me/Desktop/" & Range("G41").Value & ".pdf", Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
End Sub
I thought to save to ThisWorkbook.Path and modified the above.
Sub SavetoPdf()
' Saves active sheet as PDF file.
Dim Name As String
Name = ThisWorkbook.Path & "/" & Range("G41").Value & ".pdf"
Range("E31:I54").Select
Application.CutCopyMode = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=Name, _
Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
I am on a Mac.
I get
Error on Printing
and the debugger highlights this code:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=Name, _
Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
You title reads that you want to PDF a "Range" of cells. Is that what is not working for you?
Sub SavetoPdf()
' Saves active sheet as PDF file.
Dim Name As String
Name = ThisWorkbook.Path & "/" & Range("G41").Value & ".pdf"
Range("E31:I54").ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _
Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
Modified #Davesexel code: Tested on mock data and saved no problem.
Dim rng As Range
Dim Name As String
Set rng = Worksheets("Sheet1").Range("G41") 'Change worksheet to your needs
Name = rng.Value
Range("E31:I54").ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "/" & Name & ".pdf", _
Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
I recorded a macro.
It works if all of the sheets are visible but when I hide a sheet it will not save to pdf.
This is the code.
Sub save_pdf()
'
' save_pdf Macro
'
'
Sheets(Array("TITLE", "CML", "CLUSTER", "ORS", "MOBILE", "YPS", "DEVICES", "PORTS")).Select
Sheets("TITLE").Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _ Sheets("MAIN").Range("customer_name") + " - Project Initiation_ Document.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True,_ IgnorePrintAreas:=False, OpenAfterPublish:=True
Sheets("MAIN").Select
End Sub
Something like this:
Sub ExportVisible()
Dim shts, sht As Worksheet, s, i As Long
shts = Array("TITLE", "CML", "CLUSTER", "ORS", "MOBILE", "YPS", "DEVICES", "PORTS")
i = 0
For Each s In shts
Set sht = ActiveWorkbook.Sheets(s)
If sht.Visible = xlSheetVisible Then
i = i + 1
sht.Select (i = 1) '"replace" parameter true when i=1
End If
Next s
'Sheets("TITLE").Activate '<<EDIT: remove this
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=Sheets("MAIN").Range("customer_name").Value & _
" - Project Initiation_Document.pdf ", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
It's likely due to the use of .Select. We want to avoid using .Select wherever possible. Instead, just set a loop to go through each worksheet in your workbook.
Sub save_PDFs()
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Worksheets
sht.ExportAsFixedFormat Type:=xlTypePDF, fileName:=Sheets("MAIN").Range("customer_name") + " - Project Initiation_ Document.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
Next sht
End Sub
However, if you want only visible sheets, then do this:
Sub save_PDFs()
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Worksheets
If sht.Visible = True Then sht.ExportAsFixedFormat Type:=xlTypePDF, fileName:=Sheets("MAIN").Range("customer_name") + " - Project Initiation_ Document.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
Next sht
End Sub