Macro Button to Print sheet as PDF, but name that Sheet off several cells

Aussie5380

New Member
Joined
Sep 30, 2022
Messages
32
Office Version
  1. 2019
Platform
  1. Windows
I'm trying to make a print button Macro that prints to pdf, but also names the file based on vales in several cells.

I would like the naming convention to look like this:

Cells on Sheet:
F12 - First Name
F13 - Surname
F14 - Staff Number

What i want the save name to look like is this:

SURNAME, First name - Staff number - Leave Loading.PDF

SMITH, John - 89569812 - Leave Loading.PDF


Is this achievable? Im still quite new to macro writing, and any help would be greatly appreciated.

My print code so far looks like this, just not sure how to add the naming convention?

Sub print_sheets_by_name()

Worksheets("Leave Loadiing").PrintOut

End Sub

I have also tried to add these lines but im getting errors back and im not sure what im missing:

Dim FileName As String
FileName = Worksheets("Leave Loading").Range("F13") & (",") & ("F12") & "-" & ("F14") & "Leave Loading" & ".pdf"

Worksheets(PrintSheets).ExportAsFixedFormat _
Type:=xlTypePDF, _
FileName:=FileName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True


Thanks in advance!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Maybe. (Saves into same folder where your excel workbook with the code has been saved into)
Code:
Sub For_Down_Under()
Dim sh1 As Worksheet, fn As String
Set sh1 = Worksheets("Sheet1")    '<----- Change as needed
fn = sh1.Range("F13").Value & ", " & sh1.Range("F12").Value & " - " & sh1.Range("F14").Value & " Leave Loading"
sh1.PrintOut , , , , , True, , ThisWorkbook.Path & "\" & fn & ".PDF"
End Sub
 
Upvote 0
Solution
T
Maybe. (Saves into same folder where your excel workbook with the code has been saved into)
Code:
Sub For_Down_Under()
Dim sh1 As Worksheet, fn As String
Set sh1 = Worksheets("Sheet1")    '<----- Change as needed
fn = sh1.Range("F13").Value & ", " & sh1.Range("F12").Value & " - " & sh1.Range("F14").Value & " Leave Loading"
sh1.PrintOut , , , , , True, , ThisWorkbook.Path & "\" & fn & ".PDF"
End Sub
Thank you heaps!
 
Upvote 0

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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