Thursday, 7 February 2013

How To Save each Sheet Of a Work Book as PDF File

Excel VBA Macro To Save Each Sheet in ThisWorkBook as a PDF File
'This Macro Prints Each sheet of Thisworkbook[i.e. The workbook in which you use this macro code].
'If you want to run this macro on any Active Work Book , Please edit as you desire.

Sub PrintMyWorkbook2Pdf()

Dim WB As Object
Dim WS As Worksheet
Dim MyFilePath As String
Dim PdfFileName As String
Dim PdfFilesFolder As String

On Error Resume Next

Set WB = ThisWorkbook
PdfFilesFolder = ThisWorkbook.Name & "_" & "PDFs"
MyFilePath = "C:\Documents and Settings\Administrator\My Documents\"

MkDir MyFilePath & PdfFilesFolder & "\"

PdfFileName = ActiveSheet.Name

For Each WS In WB.Sheets


ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _

FileName:=MyFilePath & PdfFilesFolder & "\" & ActiveSheet.Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False

Next WS

End Sub


The Macro Replace the Previous Pdf Files with the Latest Files Every Time You Run 

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your open Feedback only related to this Blog Posts. Please note that I cannot respond to the Anonymous Comments.

Subscribe to Blog Posts by Email

ExcelKingdom-Popular Posts