Export each Sheet to PDF file in Excel by Using VBA Macros

Have you ever created a PDF from a Sheet in Excel? Easy isn’t it?

Creating PDF files from sheets in Excel is an easy job. What if in the Excel file there are lots of sheets. For example, a report from sales in one month for each excel file consisting of 30 days, where each day’s report is stored in a different sheet. Or maybe each excel file contains hundreds of sheets and you have to create a PDF file of each sheet.

excel export pdf 01

Pekerjaan yang mudah menjadi berat jika volumenya sangat besar. Tapi tidaEasy work becomes heavy if the volume is very large. But don’t worry, using macros from Excel will not be a problem.

Export Excel sheet to PDF with Macro VBA

  1. Open Excel Macros, see how to create macros.
  2. Copy the following script
Sub ExportToPDFs()
' Bardimin
' Export Sheet to PDF
' Save Each Worksheet to a separate PDF file.
 
Dim ws As Worksheet
Dim myFile As String
myFile = Application.ActiveWorkbook.Path

For Each ws In Worksheets
ws.Select
sheetName = ws.Name
 
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=myFile & "" & sheetName & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
 
Next ws
End Sub
  1. Run Macro
excel export pdf 02

The macro export sheet to PDF will produce a PDF file with a name like a sheet name in Excel that you created and saved in the directory from the same as your excel file.

To change the name of the resulting PDF file, you can change the following line of code

Filename:=myFile & "" & sheetName & ".pdf", _

Good luck ……

Latest Articles