How to save a spreadsheet that was converted to a pdf to a file location

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
The goal I am trying to achieve is to convert a spreadsheet to a pdf, save the pdf to a specified folder, and email that pdf all with a click of a button. However I am stuck on the second part, saving the new converted pdf to a specified file location. Here's what I have so far, everything works great until the last line of code.
Code:
ActiveWorkbook.SaveAs filename:=sPath
I get Runtime error '1004': Application defined or object-defined error.
VBA Code:
Private Sub btnSave_Email_Click()
    Dim sPath As String
    Dim sFilename As String
    
    sPath = "C:\Users\UserName\Desktop\Saved PDF TEST\"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF
    ActiveWorkbook.SaveAs filename:=sPath
    
End Sub

Thank You
 
Is there a way to add/append a time date stamp after the PDF name followed by ".pdf"
Ex:
CravingFish_7/21/2020_14:11:23.pdf

Without an error message occurring.

Thank you
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You would need to format the date and concatenate the file name, date and time and the file extension. Please also be aware you can't use the forward slashes as they would represent folders that don't exist. Example below.

FileName:= "CravingFish" & Format(Now(),"M-DD-YY H-MM-S")&".PDF"
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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