Code required to PDF a worksheet with a specific filename within the workbook to a specific location

Tonyd789

Board Regular
Joined
Feb 6, 2011
Messages
89
Good evening all, I'm hoping that one of you very clever people can help me out with this request.

I'm after a macro where i push a button within the workbook that will PDF one of the worksheets within the workbook.
I would like the code to save it in a certain folder on the computer with a file name taken from a cell in the workbook and also add the date to the file name.

Hope that makes sense, thanks in advance for any help provided.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hello. Try this out.

VBA Code:
Sub savetoPDF()

'Declares current sheet as the sheet to export, change to suit
    Dim ws As Worksheet: Set ws = ActiveSheet 'or something like Sheets("Sheet1")

'The file path is set to the path of this workbook, change to suit
    Dim fPath As String: fPath = ThisWorkbook.Path

'The file name is set to PDF Output, change range to suit
    Dim fName As String: fName = ws.Range("A2").Value & "_" & Format(Date, "mmddyyyy")

'The complete save as string
    Dim sPath As String: sPath = fPath & "/" & fName & ".pdf"

'Exports the sheet to PDF
    ws.ExportAsFixedFormat xlTypePDF, sPath

End Sub
 
Upvote 0
Or in a condensed form.
Change Sheet, Folder and Cell reference as required.
Code:
Sub Condensed()
    Sheet1.PrintOut , , , , , True, , "C:\Folder Name Here\" & Range("D4").Value & " " & Format(Date, "mm-dd-yyyy") & ".PDF"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top