How to Save Selection in Excel as PDF?

Excel has some great features that make it really easy to export workbooks, worksheets, and even parts of a worksheet to a number of other formats.

Some of these formats include CSV, XML, XPS, PDF, and a whole lot of other formats.

If you’ve ever tried saving or exporting from Excel to PDF, you might have found that the active sheet gets saved by default. But what if you want to save just a part of the worksheet, rather than the whole sheet itself?

For example, say you have the following data set, and you only want to save the first 4 columns (the shaded area) to PDF, not the entire sheet.

Dataset where selected selection need to be saved as PDF

In this tutorial, we will explain how you can save a selected range of cells as a PDF format file in Excel. We will look at three ways to do this.

Throughout this tutorial, we will be using the following dataset.

We will apply the above three methods to save only the shaded portion of the sheet to PDF.

Dataset where selected selection need to be saved as PDF

Method 1: Saving a Selection to PDF using the Save As Dialog Box

This is a very commonly used method as it is simple and can usually be applied to any Excel version.

To save a selected range of cells to PDF, here are the steps that you need to follow:

  1. Select the range of cells that you want to save in the PDF file. In our example, we will select the range A1:F18.
  2. Click on the File tab.
  3. Select Save As from the options on the left sidebar (if you’re on older versions of Excel, select Save As from the File menu).Click on Save As
  4. If you are asked which folder you want to save to, then select the relevant folder.
  5. This will open the Save As dialog box. In the field next to ‘File Name’, type the name you want to give the new file, if you want to save the PDF with a different name. If not, then leave the filename as it is.File Name in Save as dialog box
  6. In the field next to ‘Save As Type’, click on the dropdown arrow.Click on the Save as type drop down icon
  7. From the dropdown menu that appears, select PDF.Select PDF as the file type
  8. Click on the Options button (located towards the bottom of the dialog box).Click on the options button in the save as dialog box
  9. This will further open a new dialog box for you to enter your options.
  10. Under the ‘Publish what’ section, select the radio button next to the ‘Selection’ option.In the options dialog box, click on Selection
  11. Click OK to close the Options dialog box.
  12. You will see more options at the bottom of the Save As dialog box, like options for optimizing your PDF file, and opening the PDF file after publishing. Check or uncheck the options that you need.
  13. Finally, click on Save to save the selection and close the Save As dialog box.Click on Save
  14. Wait for Excel to publish the PDF.

You will find the selected range of cells saved into a PDF file. If you had checked the box next to ‘Open file after publishing’, Excel will open your saved selection in your default browser or PDF viewer.

PDF opened in browser

Note: Once you have converted it to PDF, you cannot revert it back into an Excel sheet. The good thing, however, is that this is just a copy, so your original Excel sheet remains preserved the way it was.

Method 2: Saving a Selection to PDF using the Publish As Dialog Box

This method is suitable for you if you are using Excel versions 2007 and higher. It takes advantage of Excel’s built-in PDF converter. Here are the steps you need to follow:

  1. Select the range of cells that you want to save in the PDF file. In our example, we will select the range A1:F18.
  2. Click on the File tab.
  3. Select Export from the options on the left sidebar.
  4. On the right-hand side, you will see a button that says ‘Create PDF/ XPSCreate PDF XPS
  5. This will open the Publish As dialog box.Publish as dialog box
  6. Select the folder you want to save the PDF in.
  7. In the field next to ‘File Name’, type the name you want to give the new file if you want to save the PDF with a different name. If not, then leave the filename as it is.Type the name in the field
  8. In the field next to ‘Save As Type’, you will find the ‘PDF’ option already selected.
  9. Click on the Options button (located towards the bottom of the dialog box).Click on the options button
  10. This will further open a new dialog box for you to enter your options.
  11. Under the ‘Publish what’ section, select the radio button next to the ‘Selection’ option.In the options dialog box, click on Selection
  12. Click OK to close the Options dialog box.
  13. Choose your optimization (optional). You will see more options at the bottom of the Publish As dialog box, like options for optimizing your PDF file and opening the PDF file after publishing. Check or uncheck the options that you need.
  14. Finally, click on Publish to save the selection and close the Publish As dialog box.Click on Publish
  15. Wait for Excel to publish the PDF.

You will find the selected range of cells saved into a PDF file. If you had checked the box next to ‘Open file after publishing’, Excel will open your saved selection in your default browser or PDF viewer.

PDF opened in browser

Also read: VBA to Print Range of Cells to PDF

Method 3: Saving a Selection to PDF using VBA

There may be cases where you need a number of selections saved as separate PDFs in a single folder. In such cases, this method works really well and can reduce the amount of time you spend clicking and exporting.

By using VBA, you can get multiple selections saved in quick succession. The following code lets you save a selection to PDF in the same folder as the original Excel file:

Sub SaveSelectionToPDF()
Dim rng As Range
Dim newpdfname As String
Dim pdfpath As String
Set rng = Application.Selection
newpdfname = Application.InputBox("Please Enter a name for the new PDF")
pdfpath = ThisWorkbook.Path & "\" & newpdfname
rng.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=pdfpath, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub

To apply the above script, to your dataset, follow these steps:

  1. From the Developer Menu Ribbon, select Visual Basic.
  2. Once your VBA window opens, Click Insert->Module. Copy the code given above and paste it into the module window.
  3. Your code is now ready to run and use whenever needed. Close the VBA window.
  4. Now go to your worksheet and select the range of cells that you want to save to PDF (cells A1:F18 in our example).
  5. Click on Macros, under the Developer tab.
  6. This will open the Macros dialog box. Select the name SaveSelectionToPDF from the list of macros displayed.
  7. Click Run.
  8. Your code should now run. You will see a prompt asking you to enter a name for the new PDF.
  9. Enter the name you want to save the new PDF with and click OK.

You will find the selected range of cells saved into a PDF file. Excel should open your saved selection in your default browser or PDF viewer.

Explanation of the Code

Let us take a close look at what was actually happening in the above code.

  • In this code, we first created three variables, one Range variable called ‘rng’ and two string variables named ‘newpdfname’ (to hold the name for the new PDF file) and ‘pdfpath’ (to hold the path for the new PDF file).
Dim rng As Range
Dim newpdfname As String
Dim pdfpath As String
  • Next, we set the variable rng to hold the range of cells selected by the user.

Set rng = Application.Selection

We used the InputBox function to prompt the user to enter a name for the new PDF.

We stored the value entered in the string newpdfname. We added this to the path of the original Excel workbook, pdfpath (because we want to save the new PDF to the same folder as the original Excel workbook).

newpdfname = Application.InputBox("Please Enter a name for the new PDF")
pdfpath = ThisWorkbook.Path & "\" & newpdfname
  • Finally, we use the ExportAsFixedFormat method of the Range class to save the selected range of cells as PDF. In this line,
    • we defined the type as xlTypePDF, since we want to save as PDF.
    • we set the filename to the entire path stored in string pdfpath.
    • we set the quality of the PDF to xlQualityStandard.
    • we set IncludeDocProperties to True, because we want the resultant PDF to have the properties of a document.
    • we set IgnorePrintAreas to True, because we want the code to ignore any print areas already set in the worksheet.
    • we set OpenAfterPublish to True because we want the created PDF to open in a browser or PDF viewer automatically, once published. You can set this to False if you plan to save multiple PDFs, since then you wouldn’t want to open so many tabs to display the PDFs created.
rng.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=pdfpath, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=True, _
OpenAfterPublish:=True

If you intend to publish multiple selections as multiple PDFs, you can create a Quick Access button to quickly run the code with just a click.

Also read: How to Convert PDF to Excel without Software?

Advantages of Saving to PDF

Saving Excel worksheets (or a selection from them) has a few advantages, especially if you want to share or send the document with others. Some of these include:

  1. Keeping the layout, format, fonts, and images just the way you created it. Oftentimes, if the receiver has different Excel versions or formatting settings different from the receiver, the data gets re-formatted and often spoils the overall effect the sender was hoping to project. By saving the document as a PDF, the sender ensures that there are no formatting changes to the original document when the sender opens it.
  2. Avoiding accidental changes to the original document. A PDF document is usually read-only. This means, no one can tamper with it either accidentally or deliberately.
  3. The user can view the document on any device (computer, or handheld device) that has a PDF viewer (which most devices come with these days anyway!). He/she does not need to have a special spreadsheet software installed in their device.
  4. A PDF is also easier to print and distribute.

In this tutorial, we saw three ways to save or export a selection of cells to PDF.

The first method involves the use of the Save As dialog box, the second one involves the use of the Publish As dialog box and the third one involves the use of VBA code.

We hope you found the instructions laid out in this tutorial helpful and easy to follow.

Other Excel tutorials you may like:

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.

1 thought on “How to Save Selection in Excel as PDF?”

Leave a Comment