Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Printing to PDF

I wrote a macro to automatically select sheets and print to a PDF
file. Is there a way to direct the pdf file to be saved to a certain
file each time(ie C:\My Documents\PDF)?

The Save as PDF box defaults to the last location I saved the excel
document or printed a pdf to (ie Desktop)


Thanks

John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Printing to PDF

John,

I take no credit for the code I found it (can't remember where)

Dim PDFFileName As String
PSFileName = "c:\myPostScript.ps"
PDFFileName = "c:\myPDF.pdf"

' Print the Excel range to the postscript file
Dim MySheet As Worksheet
Set MySheet = ActiveSheet
ActiveSheet.PrintOut copies:=1, preview:=False, ActivePrinter:="Acrobat Distiller", printtofile:=True, collate:=True,
prtofilename:=PSFileName

' Convert the postscript file to .pdf
Dim myPDF As PdfDistiller
Set myPDF = New PdfDistiller
myPDF.FileToPDF PSFileName, PDFFileName, ""

Kill (PSFileName)

End Sub

Requires references to distiller and pdfmaker.

Dan E

"John" wrote in message om...
I wrote a macro to automatically select sheets and print to a PDF
file. Is there a way to direct the pdf file to be saved to a certain
file each time(ie C:\My Documents\PDF)?

The Save as PDF box defaults to the last location I saved the excel
document or printed a pdf to (ie Desktop)


Thanks

John



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Printing to PDF

Sorry,

posted incomplete code

Private Sub CommandButton1_Click()
' Define the postscript and .pdf file names.
Dim PSFileName As String
Dim PDFFileName As String
PSFileName = "c:\myPostScript.ps"
PDFFileName = "c:\myPDF.pdf"

' Print the Excel range to the postscript file
Dim MySheet As Worksheet
Set MySheet = ActiveSheet
ActiveSheet.PrintOut copies:=1, preview:=False, ActivePrinter:="Acrobat Distiller", printtofile:=True, collate:=True,
prtofilename:=PSFileName

' Convert the postscript file to .pdf
Dim myPDF As PdfDistiller
Set myPDF = New PdfDistiller
myPDF.FileToPDF PSFileName, PDFFileName, ""

Kill (PSFileName)

End Sub

If you wanted a different PDFFileName put in something like

ChDir ("C:\My Documents\PDF\")
PDFFileName = Application.GetSaveAsFilename("PDF Output.pdf", "PDF, *.pdf")
If PDFFileName = "False" Then
MsgBox Prompt:="PDF Not Saved, No name specified"
Exit Sub
End If

Dan E

"John" wrote in message om...
I wrote a macro to automatically select sheets and print to a PDF
file. Is there a way to direct the pdf file to be saved to a certain
file each time(ie C:\My Documents\PDF)?

The Save as PDF box defaults to the last location I saved the excel
document or printed a pdf to (ie Desktop)


Thanks

John





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003 printing problem--printing 1 document on 2 pages Bons Excel Discussion (Misc queries) 0 December 24th 09 04:15 PM
Printing allstarmanage Excel Discussion (Misc queries) 2 September 8th 09 09:40 PM
Excel Printing --Borders are not printing on the same page as data Stup88 Excel Discussion (Misc queries) 1 August 7th 07 09:34 AM
Printing a heading on each new page when printing Brian Excel Discussion (Misc queries) 3 November 15th 06 05:22 PM
Enable Double sided printing contiuously when printing multiple s. Lee Excel Discussion (Misc queries) 1 November 27th 04 01:58 AM


All times are GMT +1. The time now is 07:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"