CAPtain232
Board Regular
- Joined
- Oct 13, 2011
- Messages
- 197
Can someone help me write a macro to save the active worksheet as a PDF with filename referencing cell A1
Thank you
Thank you
Private Sub CommandButton2_Click()
'This macro opens the SaveAs option with the defult file path "you have to set this file path below" coverts the whole sheet into .pdf file format
'And opens the .pdf to view <-- you can disable the view after covert option with lower code: OpenAfterPublish:=False
pdfName = ActiveSheet.Range("T1")
ChDir "C:\Temp\" 'This is where youo set a defult file path.
fileSaveName = Application.GetSaveAsFilename(pdfName, _
fileFilter:="PDF Files (*.pdf), *.pdf")
If fileSaveName <> False Then
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
fileSaveName _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
End If
MsgBox "File Saved to" & " " & fileSaveName
End Sub
@CAPtain
Hi
Please try the below code
Code:Private Sub CommandButton2_Click() 'This macro opens the SaveAs option with the defult file path "you have to set this file path below" coverts the whole sheet into .pdf file format 'And opens the .pdf to view <-- you can disable the view after covert option with lower code: OpenAfterPublish:=False pdfName = ActiveSheet.Range("T1") ChDir "C:\Temp\" 'This is where youo set a defult file path. fileSaveName = Application.GetSaveAsFilename(pdfName, _ fileFilter:="PDF Files (*.pdf), *.pdf") If fileSaveName <> False Then ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _ fileSaveName _ , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _ :=False, OpenAfterPublish:=True End If MsgBox "File Saved to" & " " & fileSaveName End Sub
Thanks
Patnaik
Hello All
Thank you for providing such a great support to people like me.
I don't know VBA but understand basic and make changes in the back ground.
I have 2mb file of excel and want to make pdf of a sheet only. I am using following macro which is working fine as it is picking certain cells in file name.
My issue is it is saving in the same folder where file location is (which I guess coming from ".path") I need it to save in C:\XYZ folder but file name needs to be same as macro
Sub Save_ActSht_as_Pdf()
' Saves active sheet as PDF.
Dim Name As String
Name = ThisWorkbook.Path & "" & ActiveSheet.Name & Range("D11") & " Batch # " & Range("D15") & " " & Range("D34") & _
Format(Now(), " mm.dd.yy hh.mm") & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
Please correct the code to put the file in C:\XYZ folder. I can ensure it will create the XYZ folder itself, if it can't find one.
Thanks in advance.
Thank you, I was able to do it.
Try this, with the sheet names exactly as written above - is there really a space before all the sheet names except Sheet5?I need to change the printing of all specified sheets to be saved in one PDF file
Rich (BB code):'Printing sheets in order Dim SheetsArray As Variant Dim i As Integer SheetsArray = Array("Sheet5", " Sheet6", " Sheet8", " Sheet10", " Sheet11", " Sheet14", " Sheet15") For i = 0 To UBound(SheetsArray) Sheets(SheetsArray(i)).PrintOut Copies:=1 Next i Application.ScreenUpdating = True End Sub
Public Sub Save_Multiple_Sheets_As_One_PDF()
Dim currentSheet As Worksheet
With ThisWorkbook
Set currentSheet = .ActiveSheet
.Worksheets(Array("Sheet5", " Sheet6", " Sheet8", " Sheet10", " Sheet11", " Sheet14", " Sheet15")).Select
.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\Multiple Sheets.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
currentSheet.Select
End With
End Sub