Jyotirmaya
Board Regular
- Joined
- Dec 2, 2015
- Messages
- 205
- Office Version
- 2019
- Platform
- Windows
VBA Code:
'This method Saves each of the worksheets of current
'Excel file as individual PDF File using Excel VBA
Sub SaveEachSheetAsPDFFileED()
Dim wsA As Worksheet
Dim wbA As Workbook
Dim WS_Count As Long
Dim strFile, myfile As String
Set wbA = ActiveWorkbook
WS_Count = wbA.Worksheets.Count
For Each wsA In wbA.Sheets
wsA.Activate
'create default name for savng file
strFile = "C:\Users\jyotirmaya\Desktop\Macro\" & wsA.Name & " " & Format(Date, "dd-mm-yyyy") & ".pdf"
myfile = strFile
'export to PDF if a folder was selected
If wsA.Name = "COUNT" Or wsA.Name = "RAW DATA" Then
'no code here
Else
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myfile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
Next
End Sub
I am using this code to print as PDF all sheets of the excel except COUNT& RAW DATA sheet. In count sheet in Column A I have sheet names and in column B i have the information of number of rows data available in the sheet. I want that ifthe value of column B is more than 0 then only that sheet will be saved as PDF. Presently all the sheets are saving as pdf even blank sheets
In COUNT sheet Column B, I am using formula =COUNTIF(INDIRECT("'"&A1&"'!E:E"),"<>")-1 to count the number of rows data. I want that if this formula results more than zero then only the PDF will be made.