+ Reply to Thread
Results 1 to 2 of 2

Thread: Macro to save worksheet as PDF

  1. #1
    Registered User
    Join Date
    04-02-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    89

    Macro to save worksheet as PDF

    Hello,

    I am looking for a macro that saves page 1 of a worksheet as a PDF and then, if the PDF has to open during the process, for the PDF to close in order to complete other instructions within the macro.

    Any help would be awesome.

    Thanks in advance!

  2. #2
    Valued Forum Contributor Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    2010
    Posts
    952

    Re: Macro to save worksheet as PDF

    'same as: http://www.mrexcel.com/forum/showthread.php?p=2850609
    Sub Test_PublishToPDF()
      Dim sDirectoryLocation As String, sName As String
      
      sDirectoryLocation = ThisWorkbook.Path
      sName = sDirectoryLocation & "\" & Range("E4").Value2 & ".pdf"
      PublishToPDF sName, activeworksheet
    End Sub
    
    Sub PublishToPDF(fName As String, ws As Worksheet)
      Dim rc As Variant
      
      'ChDrive "c:"
      'ChDir GetFolderName(fName)
      rc = Application.GetSaveAsFilename(fName, "PDF (*.pdf), *.pdf", 1, "Publish to PDF")
      If Not rc Then Exit Sub
      
      ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fName _
      , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
      :=False, OpenAfterPublish:=False
    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.2.0