Save excel worksheets to PDF with macro?

February 10, 2011 at 01:02:14
Specs: Windows Vista
Hello, I need to save diffrent worksheets with the tag "save" in cell A1 to a PDF file with a macrobutton.

I Find this 2 code, Please could anyone help me to combine this two codes, or is there any other solution?

[I need the fucntion that says, just youse thw worksheets with "save" in A1, and combine it with the seconde code that print PDF]

--code 1---

Sub Test5()
Dim sht As Worksheet

For Each sht In ThisWorkbook.Worksheets
If sht.Range("save").Value <> "" Then
End If
Next sht

End Sub

--code 2---
Sub Save_as_pdf()
Dim FSO As Object
Dim s(1) As String
Dim sNewFilePath As String

Set FSO = CreateObject("Scripting.FileSystemObject")
s(0) = ThisWorkbook.FullName

If FSO.FileExists(s(0)) Then
'//Change Excel Extension to PDF extension in FilePath
s(1) = FSO.GetExtensionName(s(0))
If s(1) <> "" Then
s(1) = "." & s(1)
sNewFilePath = Replace(s(0), s(1), ".pdf")

'//Export to PDF with new File Path
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=sNewFilePath, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
End If
'//Error: file path not found
MsgBox "Error: this workbook may be unsaved. Please save and try again."
End If

Set FSO = Nothing

End Sub

Please help me :)

See More: Save excel worksheets to PDF with macro?

February 10, 2011 at 01:19:01
I found this code, and it works, BUT I want to create a PDF file with more than one worksheet...

Sub pdfsave()

pdfname = Range("A1").Value

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfname, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
End Sub

Report •
Related Solutions

Ask Question