Save as PDF using cell value

Lux Aeterna

Board Regular
Joined
Aug 27, 2015
Messages
191
Office Version
  1. 2019
Platform
  1. Windows
Hello everyone!

Although it has been asked an answered many times, I am not able to do it!

I'd like the active sheet printed as PDF at a specific folder C:\Users\pc50\Desktop\Appointments2022, using either cell value (I2) or that day's date inverted (yyyy-mm-dd), whichever is simpler to use (colleagues are not much used to using computers).

Using the F12 key for that would be ideal, but any other shortcut is ok too.

Thank you in advance and apologies for my incompetence!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Here's a sample macro that you can assign as required:

VBA Code:
Sub ExportSheetToPDF()
   Const SAVE_FOLDER As String = "C:\Users\pc50\Desktop\Appointments2022\"
   
   Dim FileName As String
   FileName = Format(Date, "yyyy-mm-dd") & ".pdf"
   
   Dim ws As Worksheet
   Set ws = ActiveSheet
   
   ' delete any existing version first
   If Dir(SAVE_FOLDER & FileName) <> vbNullString Then Kill SAVE_FOLDER & FileName
   
   ' save to PDF
   ws.ExportAsFixedFormat xlTypePDF, SAVE_FOLDER & FileName
End Sub
 
Upvote 0
Solution
Here's a sample macro that you can assign as required:

VBA Code:
Sub ExportSheetToPDF()
   Const SAVE_FOLDER As String = "C:\Users\pc50\Desktop\Appointments2022\"
 
   Dim FileName As String
   FileName = Format(Date, "yyyy-mm-dd") & ".pdf"
 
   Dim ws As Worksheet
   Set ws = ActiveSheet
 
   ' delete any existing version first
   If Dir(SAVE_FOLDER & FileName) <> vbNullString Then Kill SAVE_FOLDER & FileName
 
   ' save to PDF
   ws.ExportAsFixedFormat xlTypePDF, SAVE_FOLDER & FileName
End Sub
Thank you for your reply! Where can I copy/paste this macro?

Found the VBA editor. What's the shortcut for it?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,770
Members
449,049
Latest member
greyangel23

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