Public Sub MakePDF(ByVal strPDFFileName As String)
' Define the postscript and .pdf file names.
Dim strPSFileName As String
Dim xlWorksheet As Worksheet
Dim objPdfDistiller As PdfDistiller
strPSFileName = Left(strPDFFileName, InStrRev(strPDFFileName, "/")) & "tmpPostScript.ps"
' Print the Excel ActiveSheet to the postscript file
Set xlWorksheet = ActiveSheet
Call xlWorksheet.PrintOut(copies:=1, preview:=False, ActivePrinter:="Acrobat Distiller", printtofile:=True, collate:=True, prtofilename:=strPSFileName)
' Convert the postscript file to .pdf
Set objPdfDistiller = New PdfDistiller
Call objPdfDistiller.FileToPDF(strPSFileName, strPDFFileName, "")
' Finally, delete the postscript file
Call Kill(strPSFileName)
End Sub
程序调用的时候,需要修改Adobe PDF Settings的默认设置:
开始菜单 ⇒ 设定 ⇒ 打印机 ⇒ 选择Adobe PDF,右键选属性 ⇒ 选择"详细设定"选项卡 ⇒ 点击"标准设定"按钮 ⇒ 钩选掉"Do no send fonts to 'Adobe PDF'"
调用: Sub MakePDFApp() Call MakePDF("c:/firefox.pdf") End Sub 这样就能在指定位置生成指定的PDF文件了。