macro to print to pdf with a cell value as the file name. the page to pdf is on a different tab

nreyes601

New Member
Joined
Feb 27, 2025
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Sub printtopdf()
'
' printtopdf Macro
'

'
Sheets("Ticket").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
"C:\Users\Nina\Pit Office-Tickets Dropbox\Pit Office-Tickets Team Folder\Main Testing\3.pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
Sheets("Form").Select
Range("C3").Select
End Sub
 
Hi and welcome to MrExcel board!

with a cell value as the file name

In the macro, adjust the values in blue for the name of your sheet and cell where you have the name of the file.

Rich (BB code):
Sub printtopdf()
  Dim NamePdf As String
  Dim PathPdf As String
 
  NamePdf = Sheets("Form").Range("B2").Value
  PathPdf = "C:\Users\Nina\Pit Office-Tickets Dropbox\Pit Office-Tickets Team Folder\Main Testing\"
 
  Sheets("Ticket").ExportAsFixedFormat Type:=xlTypePDF, Filename:=PathPdf & NamePdf & ".pdf", _
    Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub

:giggle:
 
Upvote 0

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