locked
Macro to print and create PDF at the same time. RRS feed

  • Question

  • I have the following macro for printing. I would like to print and save as PDF at the same time,and rename the PDF file with information in certain cells.

    Following is the code 

    Sub statement() ' ' statement Macro ' ' ' Range("af3:An95").Select ActiveSheet.PageSetup.PrintArea = "$af$3:$An$95" ActiveWindow.SelectedSheets.PrintPreview Range("af3").Select End Sub

    All help will be very much appreciated.

    Thank You

    Rafik

    Wednesday, August 12, 2015 3:38 PM

Answers

  • Hi Rafik,

    Based on my understanding, we can use worksheet.printout method to print the specific worksheet. And we can use Worksheet.ExportAsFixedFormat to export to a file of the PDF format and here is an sample that export the active sheet with the file name from A1 to disk for your reference:

        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            "C:\" & Range("A1"), Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
            True
    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, August 13, 2015 5:22 AM

All replies

  • Can you simply turn on the Macro Recorder and save as PDF?  That should give you the exact code you need.

    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.


    • Edited by ryguy72 Wednesday, August 12, 2015 8:28 PM
    Wednesday, August 12, 2015 8:28 PM
  • Hi Rafik,

    Based on my understanding, we can use worksheet.printout method to print the specific worksheet. And we can use Worksheet.ExportAsFixedFormat to export to a file of the PDF format and here is an sample that export the active sheet with the file name from A1 to disk for your reference:

        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            "C:\" & Range("A1"), Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
            True
    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, August 13, 2015 5:22 AM