Announcement

Collapse
No announcement yet.

Excel VBA Print to PDF

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Excel VBA Print to PDF

    Hi,

    I am trying to write a macro that prints the active sheet to a pdf file automatically.

    Here is the code Im using:

    Code:
    Sub PrintPDF()
    Application.ScreenUpdating = False
    Sheets("Sheet1").PrintOut Copies:=1, _
    ActivePrinter:="CutePDF Writer on CPW2:", PrintToFile:=True, _ Collate:=True,PrToFileName:=ModifiedSheet1.pdf
    Application.ScreenUpdating = False
    End Sub
     
    This prints a pdf like I want but I get an error when I try to open the pdf. 
     
    If I leave the code like this:
    Sub PrintPDF()
    Application.ScreenUpdating = False
    Sheets("Sheet1").PrintOut Copies:=1, _
    ActivePrinter:="CutePDF Writer on CPW2:", Collate:=True
    Application.ScreenUpdating = False
    End Sub
    It just brings up the save as dialog box and then I have to manually type in the filename, but I can open the pdf after this method.

    Am I missing something in the first method? It would be very helpful to not have to manually type in the filename every time (that's why I wrote the macro in the first place).

    Thanks,

    Craig
    Last edited by Reafidy; June 25th, 2011, 07:31.

  • #2
    Re: Excel VBA Print to PDF

    After doing a little more digging I found another person with the same issue.

    http://www.excelforum.com/excel-prog...-with-vba.html

    However I'm still unable to find a simple answer. =\

    Craig

    Comment


    • #3
      Re: Excel VBA Print to PDF

      I'm still confused as to why I am having problems with the PrToFileName parameter.

      I have tried leaving out the .pdf at the end of the PrToFileName variant however an extension-less file is created which is not helpful.

      Is anyone even able to reproduce this error?

      I'm using excel 2007 and CutePDF Writer

      Thanks,

      Craig

      Comment

      Working...
      X