Thank you for the code. I'll try it.
Main Topics
Browse All TopicsI need to convert a set of .mpp files to .pdf files automatically. I use the "FilePrintSetup" method to set "Adobe PDF" as a printer and then the "FilePrint" method. However, each time a "Print" dialog box appears and I have to enter a file name of the pdf file. Is it possible to specify a file name for a .pdf file in the code?
Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: sgaggerjPosted on 2005-08-24 at 17:37:08ID: 14748245
This code works for printing in excel to pdf without the filename dialog box (need to make sure SEND FONTS TO ADOBE is unchecked in the printers -> properties box, also prompt for filename is unchecked too)
er(pdfPrin ter), PrintToFile:=True, Collate:=True, PrToFilename:=PSfilename
--------- ---------- ---------- --------- ---
--------- ---------- ---------- --------- ---
hope it helps!
Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppname As String, ByVal LpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
Public Sub PrintToPdf(ws As Sheets, out As String, path As String)
' sheets must be VISIBLE to print -
' ActiveSheet.PageSetup must be defined for the range you want to print or the whole sheet will print
Dim myPDF As PdfDistiller, PSfilename As String, PDFfilename As String
Set myPDF = New PdfDistiller
' Define the postscript filename
PSfilename = docpath & "temp.ps"
' Define the .pdf filename
PDFfilename = out
ws.PrintOut Copies:=1, Preview:=False, ActivePrinter:=ChoosePrint
myPDF.FileToPDF PSfilename, PDFfilename, ""
Kill path & "temp.ps"
Kill path & "*.log"
End Sub
Public Function ChoosePrinter(printerType As String) As String
Dim vaList, i
'Get all printers
vaList = PrinterFind
For i = 0 To UBound(vaList)
If Mid(vaList(i), 1, 11) = printerType Then
ChoosePrinter = vaList(i)
Exit For
End If
Next i
End Function
Public Function PrinterFind(Optional Match As String) As String()
Dim n%, lRet&, sBuf$, sCon$, aPrn$()
Const lLen& = 1024, sKey$ = "devices"
'-------------------------
'written by keepITcool
'requires xl2000 or newer.
'returns a zerobased array of complete localized printer strings
'results are filtered on Match string, if no result the ubound = -1
'-------------------------
'Split ActivePrinter string to get localized word for "on"
aPrn = Split(Excel.ActivePrinter)
sCon = " " & aPrn(UBound(aPrn) - 1) & " "
'Read all installed printers (1k bytes s/b enough)
sBuf = Space(lLen)
lRet = GetProfileString(sKey, vbNullString, vbNullString, sBuf, lLen)
If lRet = 0 Then
Err.Raise vbObjectError + 513, , "Can't read Profile"
Exit Function
End If
'Split buffer string
aPrn = Split(Left(sBuf, lRet - 1), vbNullChar)
'Filter array on Match
If Match <> vbNullString Then aPrn = Filter(aPrn, Match, -1, 1)
For n = LBound(aPrn) To UBound(aPrn)
'Add 16bit portname for each Printer
sBuf = Space(lLen)
lRet = GetProfileString(sKey, aPrn(n), vbNullString, sBuf, lLen)
aPrn(n) = aPrn(n) & sCon & _
Mid(sBuf, InStr(sBuf, ",") + 1, lRet - InStr(sBuf, ","))
Next
'Return the result
PrinterFind = aPrn
End Function