Thanks to several previous threads I have the following code to create a pdf file from an Excel sheet(s):
This works fine if i run it "manually" but as soon as i put it in the workbook on_open, I get a dialog asking for an output filename. Anyone any idea what's happening?
Cheers, Craig
Si fractum non sit, noli id reficere
Code:
Sub pdfConverter()
Dim PSFileName As String, PDFFileName As String, DistillerCall As String
Dim ReturnValue As Variant
'Define the path and filenames (can get the names from a cell, and add the path & extension):
PSFileName = "\\syas2k05\intranet\demand_analysis\liveStuff\SSP\WeeklyPerformanceSummary\Archive\" & Worksheets("SSP").Range("$B$1").Value & ".PS"
PDFFileName = "\\syas2k05\intranet\demand_analysis\liveStuff\SSP\WeeklyPerformanceSummary\Archive\" & Worksheets("SSP").Range("$B$1").Value & ".PDF"
'If the files already exist, delete them:
If Dir(PSFileName) <> "" Then Kill (PSFileName)
If Dir(PDFFileName) <> "" Then Kill (PDFFileName)
'The Sendkeys characters are the full path and filename, followed by the "Enter" key.
' These are buffered until the "print to file" screen appears:
SendKeys PSFileName & "{ENTER}", False
ActiveWindow.SelectedSheets.PrintOut , PrintToFile:=True
'Add double quotes around the PS filename and PDF filename:
PSFileName = Chr(34) & PSFileName & Chr(34)
PDFFileName = Chr(34) & PDFFileName & Chr(34)
DistillerCall = "c:\Program Files\Adobe\Acrobat 6.0\Distillr\Acrodist.exe" & " /n /q /o" & PDFFileName & " " & PSFileName
'Call the Acrobat Distiller to distill the PS file. ReturnValue is zero
'if the application doesn't open correctly:
ReturnValue = Shell(DistillerCall, vbNormalFocus)
If ReturnValue = 0 Then MsgBox "Creation of " & PDFFileName & "failed."
End Sub
Cheers, Craig
Si fractum non sit, noli id reficere