How to convert Excel to Adobe PDF

后端 未结 1 801
[愿得一人]
[愿得一人] 2020-12-11 14:02

I am trying to find a code that works to convert my excel into PDF (Adobe). So far my research to find the perfect code doesn\'t work.

So here is how my company man

相关标签:
1条回答
  • 2020-12-11 14:50
    Option Explicit
    Sub SaveAsPDF()
        Dim FSO As Object
        Dim s(1) As String
        Dim FilePath 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)
                FilePath = Replace(s(0), s(1), ".pdf")
    
                '// Export to PDF with new File Path
                ActiveSheet.ExportAsFixedFormat _
                Type:=xlTypePDF, _
                Filename:=FilePath, _
                Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, OpenAfterPublish:=True
            End If
        Else
            '// Error: file path not found
            MsgBox "Error: This workbook may be unsaved.  Please save and try again."
        End If
    
        Set FSO = Nothing
    End Sub
    

    To Export the workbook Try changing ActiveSheet To ActiveWorkbook

    To Export only multiple sheets selections try using Sheets(Array("Sheet4", "Sheet5"))

    Example:

            ThisWorkbook.Sheets(Array("Sheet2", "Sheet3")).Select
            Selection.ExportAsFixedFormat _
            Type:=xlTypePDF, _
            Filename:=FilePath, _
    
    0 讨论(0)
提交回复
热议问题