Macro to convert spreadsheet to PDF?

mcgeezz

New Member
Joined
Jun 5, 2017
Messages
5
I was wondering if someone could create a macro that could convert and save a spreadsheet to a PDF, but also, save it as version 2, or anything to distinguish it from the old one if it was already saved? I'm new to excel so any help would be appreciated.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I was wondering if someone could create a macro that could convert and save a spreadsheet to a PDF, but also, save it as version 2, or anything to distinguish it from the old one if it was already saved? I'm new to excel so any help would be appreciated.

Record a macro and then add code to test to see if a previous version exists.

The basic macro looks like this: (Replace the red text with the path and filename.)

Code:
Sub Macro1()
' Macro1 Macro
'
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= "[COLOR=#FF0000]putyourfilenamehere.pdf"[/COLOR], _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=True
End Sub
 
Upvote 0
.
Paste to routine module :

Code:
Sub SavePDFTime()
Dim Path, FileName1 As String
Path = "C:\Users\My\Desktop\"
FileName1 = "Test PDF" & Format(Now(), "DD-MMM-YYYY hh mm AMPM")
ActiveWorkbook.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & FileName1 & ".pdf", OpenAfterPublish:=False
End Sub

Saves as PDF with Date and Time added to filename.
 
Upvote 0
.
Paste to routine module :

Code:
Sub SavePDFTime()
Dim Path, FileName1 As String
Path = "C:\Users\My\Desktop\"
FileName1 = "Test PDF" & Format(Now(), "DD-MMM-YYYY hh mm AMPM")
ActiveWorkbook.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & FileName1 & ".pdf", OpenAfterPublish:=False
End Sub

Saves as PDF with Date and Time added to filename.

Thank you this works perfectly! I appreciate it
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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