Macro to Save Sheet as a PDF

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,568
Office Version
  1. 2021
Platform
  1. Windows
I have text in F4 on sheet "Sales"


I would like to save the data on Sheet "Sales" as as PDF using the text in F4 as the file name


I have tried to write code to do this but get an error "Document cannot be saved ...


It would be appreciated if someonne could kindly amend my code

[Sub SaveSalesToPDF()
Sheets("Sales").Select


Application.ScreenUpdating = False
' Save a copy of the active sheet as PDF to the specified folder
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= _
"c:\Sales Reports\" & "" & ActiveSheet.Range("F4").Value & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False

Application.ScreenUpdating = True
End Sub [/code]
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi,

Try the below code

VBA Code:
Sub pdf ()
saveLocation = "C:\Sales Reports\" & Range("F4").value
Activesheet.Exportasfixedformat type:=xltypepdf, filename:=savelocation
End Sub
 
Upvote 0
Thanks for the help. My apologies -I found what was causing the issue. I had a date in the text in F4 containing / e.g 28/04/2022

Once I removed the /'s , the macro saved the sheet
 
Upvote 0
You're welcome
Glad you sorted it out
Regards,
 
Upvote 0

Forum statistics

Threads
1,215,650
Messages
6,126,016
Members
449,280
Latest member
Miahr

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