I have a series of worksheets (used as billing statements) that I need to be able to save to PDF if cell "F6" is marked "Email".
Below is some code I found online, slightly modified, however I cant seem to get it right. Any ideas?
Below is some code I found online, slightly modified, however I cant seem to get it right. Any ideas?
Code:
Sub Email_Statements()
'
' Save statments on sheets marked for "email" in PDF and
' email to the email address listed
' REQUIREMENTS: Excel 2007 with Microsoft's Save As PDF plugin.
' NOTES: Default quality is set to "xlQualityMinimum" to keep file sizes reasonable. You can change this to
' "xlQualityStandard" if you want the best detail. I have found that the xlQualityMinimum quality is fine in most cases.
' By Default this code will over-write a file of the same name if it exists in the output folder.
Dim i As Integer
Dim sOutputPath As String
Dim WSname As String
Dim ws As Worksheet
sOutputPath = "C:\Users\Public\Desktop\Test"
WSname = ActiveSheet.Name
'Loop through each worksheet
For Each ws In ActiveWorkbook.Worksheets
If CodeName <> "New" Then 'Skipp worksheet if named New
'Save each sheet marked as "Email" to PDF using OutputPath
If ws.Range("F6") = "Email" Then
Debug.Print Worksheets(WSname).Index & " " & sOutputPath & WSname
ActiveWorkbook.Sheets(i).ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
sOutputPath & WSname, Quality:=xlQualityMinimum _
, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
End If
On Error Resume Next
Next ws
End Sub