Hi all,
I have what should be an easy question. I have code that prints a PDF from a spreadsheet. I want to change it so that the file name of the printed PDF references a cell plus some text.
For example, in cell Sheet1.cells(1,1).value I have "AC/DC". I want the below code to name the PDF "AC/DC IS AWESOME.pdf". Any help would be greatly appreciated!
Sub MySheetsIntoPdf99()
Dim wsA As Worksheet
Set wsA = ActiveSheet
Call ExportSheetsAsPdf99(ThisWorkbook.Path & "/IS AWESOME.pdf", wsA)
End Sub
Sub ExportSheetsAsPdf99(FileName As String, ParamArray exportedSheets() As Variant)
Dim WB As Workbook
Dim Sheet As Object
Dim i As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set WB = Workbooks.Add
Set Sheet = exportedSheets(LBound(exportedSheets))
Sheet.Copy After:=WB.Sheets(1)
WB.Sheets(1).Delete
For i = LBound(exportedSheets) + 1 To UBound(exportedSheets)
exportedSheets(i).Copy After:=WB.Sheets(WB.Sheets.Count)
Next i
WB.ExportAsFixedFormat XlFixedFormatType.xlTypePDF, FileName, _
Quality:=xlQualityStandard, OpenAfterPublish:=False
WB.Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "PDF file has been created"
Set WB = Nothing
Set Sheet = Nothing
End Sub
Thanks,
Kelsey
I have what should be an easy question. I have code that prints a PDF from a spreadsheet. I want to change it so that the file name of the printed PDF references a cell plus some text.
For example, in cell Sheet1.cells(1,1).value I have "AC/DC". I want the below code to name the PDF "AC/DC IS AWESOME.pdf". Any help would be greatly appreciated!
Sub MySheetsIntoPdf99()
Dim wsA As Worksheet
Set wsA = ActiveSheet
Call ExportSheetsAsPdf99(ThisWorkbook.Path & "/IS AWESOME.pdf", wsA)
End Sub
Sub ExportSheetsAsPdf99(FileName As String, ParamArray exportedSheets() As Variant)
Dim WB As Workbook
Dim Sheet As Object
Dim i As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set WB = Workbooks.Add
Set Sheet = exportedSheets(LBound(exportedSheets))
Sheet.Copy After:=WB.Sheets(1)
WB.Sheets(1).Delete
For i = LBound(exportedSheets) + 1 To UBound(exportedSheets)
exportedSheets(i).Copy After:=WB.Sheets(WB.Sheets.Count)
Next i
WB.ExportAsFixedFormat XlFixedFormatType.xlTypePDF, FileName, _
Quality:=xlQualityStandard, OpenAfterPublish:=False
WB.Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "PDF file has been created"
Set WB = Nothing
Set Sheet = Nothing
End Sub
Thanks,
Kelsey