Macro to combine save selection as PDF COMBINED with using cell contents as file name not working

amandabstewart

New Member
Joined
Aug 4, 2014
Messages
45
I've tried numerous times to get a macro to save as PDF in a specific folder location combined with saving that PDF named as a cell's contents using cell J5. Just can't see what I'm doing wrong.

What does work (doesn't include cell J5 naming) is shown below. It saves the PDF as "mega" which is the name of the workbook...tis is the correct file location
Can anyone fix it to do both?

' SavePDF Macro

'

'
Range("A1:D32").Select
ChDir"C:\Users\abarker\Desktop\Orders & Inventory\ordered"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\abarker\Desktop\Orders &Inventory\ordered\MEGA.pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False,_

OpenAfterPublish:=True
End Sub


Sub SavePDF()
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try this:

Code:
Sub SavePDF()
' SavePDF Macro
Dim sName As String
'

'
sName = Range("J5").Value & ".pdf" 'Sets your filename
Range("A1:D32").Select
ChDir "C:\Users\abarker\Desktop\Orders & Inventory\ordered"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\abarker\Desktop\Orders &Inventory\ordered\" & sName, Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True

End Sub
 
Upvote 0
FINALLY FINALLY FINALLY figured out the issue--the cell "J5" had, in part, a date that no matter what either converted to a non-useful # (as excel does),or, when formatted as a date, wouldn't allow the save to occur due to characters included (e.g. the "/' symbol). So, now it is working with a different text file name in J5
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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