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

30 December 2021

Home » Blogs » Software » Export each Sheet to PDF file in Excel by Using VBA Macros

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

Creating PDF files from sheets in is an easy job. What if in the file there are lots of sheets. For example, a report from sales in one month for each 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.

TOP TUTORIALS:  Excel Merger v1.7 – Merge multiple Excel files in one file and merge multiple Sheets in one Workbook
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
TOP TUTORIALS:  How to Password Protect a Zip File in Windows 11
excel export pdf 02

The 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 ……

0 Comments