Written by Allen Wyatt (last updated October 4, 2021)
This tip applies to Excel 2007, 2010, 2013, and 2016
Brian is preparing a workbook that will be used by people without extensive Excel experience. He would like a way to be able to have them print to a PDF file with ease, perhaps with the click of a button. He has no control over what version of Excel or what operating system the people have, but he wonders if there is a way to accomplish this type of output.
Printing to PDF is relatively easy if your users are using Windows 10, as it includes (finally!) a native PDF printer driver. Unfortunately, Brian indicates that he has no control over what operating system his users have, which means he can't assume that they have the native PDF output capabilities introduced in Windows 10.
Fortunately, Excel has included (since at least Excel 2007) a way to export to a PDF file. All you need to do is choose Save As (easiest way is to press F12) and then, using the Save As Type drop-down list, choose PDF. The output is saved, automatically, in a PDF file.
If you prefer a single-button approach, you could instruct your users to add a rather esoteric tool to the Quick Access Toolbar:
Figure 1. The Quick Access Toolbar area of the Excel Options dialog box.
This new tool, when clicked, displays a dialog box that looks very similar to the Save As dialog box, except the settings are all correct for "publishing" as a PDF file.
You could also create a macro that performs the same publishing task. The macro is a good approach if you want complete control over what is included in the PDF file that is created.
Sub ExportPDF() Dim sFile As String sFile = Application.DefaultFilePath & "\" & _ ActiveWorkbook.Name & ".pdf" Sheets("Sheet1").Select ActiveSheet.PageSetup.PrintArea = "D6:K57" ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _ Filename:= sFile, Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:= True End Sub
The macro puts together a filename into the sFile variable; you should change this as desired. The macro then specifies a print area of what should be included in the PDF file. In this case, it is the range D6:K57 on Sheet1. You'll obviously want to change this to meet your needs of what you want included.
If you decide to go the macro route, you could add a button to your workbook to run the macro, making it easy for your users to create the PDF output you need.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13467) applies to Microsoft Excel 2007, 2010, 2013, and 2016.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Want a list of all the worksheets in your workbook? Here's a short, handy macro that will place all the worksheet names ...
Discover MoreIn a large worksheet, you may want to display and print just a portion of the available data. Displaying the desired ...
Discover MoreSometimes it is just easier to use the keyboard than it is to use the mouse. If you are a keyboard-oriented person, you ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2023-10-19 17:08:11
J. Woolley
@Alex
Try this macro:
Sub ActiveSheetAsPDF()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=("[" & ActiveWorkbook.Name & "]" & ActiveSheet.Name), _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
The PDF file will be saved in the active workbook's folder with a name like [Book1.xlsx]Sheet1.pdf. It will replace any file of the same name. It will open in your PDF viewer when the macro is done.
If your configuration includes the "Microsoft Print to PDF" printer (or something similar), you could also press Ctrl+P and specify that as Printer.
2023-10-19 00:58:00
Alex
Hi guys,
I was wondering if there's any solution for making exporting to PDF a simpler process.
At the moment, the steps I have to take are the following:
- Click 'Save As'
- Click 'PDF'
Then this is the part I want to fix:
- Choose Sheet (instead of workbook) - I want sheet to always be the default
- Choose 'Best for Printing' - I want this to be the default too
Any tips or advice greatly appreciated!
2019-12-15 10:31:09
J. Woolley
@Mahmoud
Try changing from ThisWorkbook.Path to ActiveSheet.Parent.Path
2019-12-15 01:14:09
Mahmoud
Hi all
I have the below macro in my worksheet to save as PDF, but users are complaining that compile error is coming ! can you pls help what could be the problem and how to solve it?
SavePDFCVSF()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "\NEW" & " " & Range("E8") & " " & Range("E20") & " " & "ETA" & " " & Range("z63") & " " & "created" & " " & Format(Now, "yyyy-mm-dd hh-mm-ss") & ".pdf", _
OpenAfterPublish:=True
ActiveSheet.Unprotect "999"
Range("fillable_fields").Select
Selection.Locked = True
Selection.FormulaHidden = True
ActiveSheet.Protect "999"
Range("E8").Select
End Sub
2019-11-04 15:17:26
Mike
Hi, I'm stuck with following issue:
I am having a number (up to 500) report diagrams to print a pdf based on an Excel data table where the charts get updated for each row, one by one. See code below:
Sub UpdateChart()
Dim tblResults As ListObject
Dim i As Integer, n As Integer
Dim PrintTo As String
n = 1
i = 1
'PrintTo = "C:\Desktop\"
Set tblResults = Worksheets("AllResults").ListObjects("MrgdResults")
n = tblResults.ListRows.Count
Worksheets("Auswertung").Activate
For i = 1 To n
tblResults.ListRows(i).Range.Copy Destination:=ActiveSheet.Range("rngAllValues")
Worksheets("Report").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=Environ("USERPROFILE") & "\Desktop\SF_Report " & Format(i, "000") & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Next
End Sub
Now the charts in the pdf file(s) get altered as regards the colors and shading, example correct image (see Figure 1 below)
and wrong pdf one (see Figure 2 below)
any suggestions?
Figure 1. good
Figure 2. bad
2019-04-19 16:26:18
Jessica Rivera
hi, I am looking to save multiple tables that are coming from a pivot and i want a macro that will go through a list of product i supply then selects them individually off a pivot and converts it to a pdf. is there a way to create a macro to do that?
2018-05-02 06:02:13
Vishrut
Above Mentioned macro works very fine but it saves file in my documents but what if i want to save pdf file in current working folder
Please advise.
2017-11-16 12:48:16
Eric Hassler
I am getting asked to push the Quick Access PDF button to all users. Is there an applicable GPO that I can use? If not could a push a registry key?
2016-09-14 18:31:44
James Avoli
May I suggest an incredible piece of freeware (or an optional pay-version with additional features) that works as a printer driver? It's "PDF reDirect" from www.exp-systems.com.
It installs as a printer for use by ALL programs, not just excel. I've not had a single problem with it since I installed it as way back in WinXP. Try it yourself then recommend it in your next newsletter (which is excel-lent IMHO).
Regards,
Jim
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments