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

WS.Activate

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _

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

Next WS

End Sub

Note:

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

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts