+ Reply to Thread
Results 1 to 2 of 2

Print to PDF

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-14-2011
    Location
    West Valley City, Utah
    MS-Off Ver
    Excel 2010
    Posts
    108

    Print to PDF

    Good afternoon all,

    Im wanting to make a macro that will save a single sheet as a pdf, and Ive done some research, but im more or less clueless.
    Last edited by Sky188; 06-06-2013 at 02:28 PM.

  2. #2
    Forum Contributor
    Join Date
    02-14-2011
    Location
    West Valley City, Utah
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Print to PDF

    I managed to find the below code, and it works quite well.
    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
        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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1