VBA code to save as PDF with cell text an date in file name

Mendonk

New Member
Joined
Apr 18, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello, Hope you are all having a lovely bank holiday weekend! I am in the throes of trying to sort out my brother in laws ridiculous method of running his business by dragging him into the world of technology. He's bought a computer (can't switch it on but its a start) so I'm trying to encourage this initiative!

I need to make things as simple as possible for him (and my sister)n to manage and as such want to create a command button that will run a macro to save the excel spreadsheet receipt as a PDF with a particular named protocol based on cells in the spreadsheet. I've been all round the houses and cant seem to find a solution so any advice you can offer would be greatly appreciated.

Basically I want it to:

a) Save as a PDF to C:\Users\Katie\Desktop\Alans Accounts
b) As Customer name (C2) - Date in cell (G3) - Text in cell (F1)

Example: McDonalds - 18-04-2022 - RECEIPT

Apologies I have tried to upload the XL2BB tool to allow me to share the template but its not working I hope the picture makes sense

Thank you in advance!


1650291575595.png
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

ranman256

Well-known Member
Joined
Jun 17, 2014
Messages
2,210
paste into a module

Code:
sub Save2Pdf()
dim vDir , vFName, vFile

vDir = "C:\Users\Katie\Desktop\Alans Accounts\"
vFName =  range("C2").value & "-" &  format(range("G3").value,"dd-mm-yyyy") & "-" & range("F1").value & ".pdf"
vFile = vDir & vFname

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= vFile, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=    False
end sub
 
Solution

Mendonk

New Member
Joined
Apr 18, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
paste into a module

Code:
sub Save2Pdf()
dim vDir , vFName, vFile

vDir = "C:\Users\Katie\Desktop\Alans Accounts\"
vFName =  range("C2").value & "-" &  format(range("G3").value,"dd-mm-yyyy") & "-" & range("F1").value & ".pdf"
vFile = vDir & vFname

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= vFile, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=    False
end sub
Huge apologies Ranman256 for not getting back to you sooner. I had family things to do. That works absolutely perfectly. Thank you so very very much!!!!
 

Forum statistics

Threads
1,181,218
Messages
5,928,749
Members
436,627
Latest member
caligirl626

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
Top