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
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 need to export excel sheet as PDF named with String and Cell Value for Example XXXY - Cell Value
Note: i do not need codes that uses path location for the saving file
I tried the following code
Sub IVI_Formatting_Export_Two_PDF ()
Dim strFilename As String
Dim srn As String Dim SWPDF As Worksheet
Set SWPDF = ThisWorkbook.Sheets ("BSS CPES MainPage")
srn = "CPE Main-Page"
strFilename = SWPDF.Range ("F7").Value
Create File name with Warehouse Name
Export2PDF
SWPDF.ExportAsFixedFormat
Type:=xlTypePDF,
Filename:=strFilename & srn,
Quality:=xl QualityStandard,
IncludeDocProperties:=False,
IgnorePrintAreas:=False,
From:=1,
To:=1,
OpenAfterPublish:=True
End Sub
You must specify a path to export PDF. Without path where it will be saved? You can use variable to specify path. Currently I have used same as file path. Your problem was in filename parameter. Try below sub.
Sub IVI_Formatting_Export_Two_PDF()
Dim strFilename As String
Dim srn As String
Dim SWPDF As Worksheet
Set SWPDF = ThisWorkbook.Sheets("BSS CPES MainPage")
srn = "CPE Main-Page"
strFilename = SWPDF.Range("F7").Value
'Create File name with Warehouse Name
'Export2PDF
SWPDF.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "\" & strFilename & "_" & srn & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=1, _
OpenAfterPublish:=True
'Clear memory
Set SWPDF = Nothing
End Sub
Here Filename:=ThisWorkbook.Path & "\" & strFilename & "_" & srn & ".pdf" will export the PDF to same folder where your workbook is located. Also you must include .pdf extension to export excel sheet as pdf.
I keep getting RunTime error of '(2147024773)8007007b' everytime I execute the macro, I don't know what I have done wrong. Any hints on how to fix this?
Dim wsA As Worksheet
Set wsA = ActiveSheet
Sheets("Main_Page").Activate
ActiveSheet.Range("A01:F30").Select
Sheets("Sheet3").Activate
ActiveSheet.Range("A01:B6").Select
Sheets(Array("Sheet1", "Sheet3")).Select
Selection.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & strFilename & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
I don't see you creating the variable and assigning a value to it you can try this. Also try avoiding select and activate.
Sub SaveMultipleSheetsAsPDF()
Dim strFilename As String
Dim sht1 As Range
Dim sht3 As Range
Set sht1 = Worksheets("Main_Page").Range("A1:F30")
Set sht3 = Worksheets("Sheet3").Range("A1:B6")
strFilename = "mySheets"
sht1.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & strFilename & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
sht3.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & strFilename & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
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
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