2

I am new to VBA and still trying to learn this day by day. I need to print my opened workbook with a .PDF format but without prompting the print dialog box(Destination folder). Instead, I want to format a destination path in the code and also with some page setups(orientation,zoom,etc). How do I solve this?

Sub PrintDoc()
Sheets("Sheet1").PrintOut
End Sub
Dragonthoughts
  • 2,180
  • 8
  • 25
  • 28
Nilusha M.
  • 57
  • 1
  • 13
  • 1
    Possible duplicate of [How do you prevent printing dialog when using Excel PrintOut method](https://stackoverflow.com/questions/67219/how-do-you-prevent-printing-dialog-when-using-excel-printout-method) – drwbns Oct 22 '18 at 23:30

1 Answers1

2

You can use the code below to define your destination path and print PDF without prompting the print dialog box and some basic page set-ups.

'Export as PDF
Application.DisplayAlerts = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    destinationPath & destinationFilename & ".pdf" _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False

Attribution: Another Stackoverflow answer

jainashish
  • 4,702
  • 5
  • 37
  • 48
  • ,I would like to thank for being kind to answer my question and helped me to solve this.Actually it worked.Thank you! – Nilusha M. Oct 24 '18 at 00:20
  • Thanks Nilusha. Request you to accept my answer by clicking the tick on the left of my answer. Glad, it helped you. – jainashish Oct 24 '18 at 00:21