如何利用excel VBA生成PDF文件

发布网友 发布时间:2022-04-22 01:01

我来回答

5个回答

热心网友 时间:2024-01-10 01:59

首先,加载引用,如图

然后,在打印机中对Acrobat Distiller的打印进行设置设置(必须,否则转化出错!)

Public Sub MakePDF(ByVal strPDFFileName As String)

            Dim strPSFileName As String

            Dim xlWorksheet As Worksheet

            Dim objPdfDistiller As PdfDistiller

             strPSFileName = Left(strPDFFileName, InStrRev(strPDFFileName, "/")) & "tmpPostScript.ps"

              Set xlWorksheet = ActiveSheet

            Call xlWorksheet.PrintOut(copies:=1, preview:=False, ActivePrinter:="Acrobat Distiller", printtofile:=True, collate:=True, prtofilename:=strPSFileName)

              Set objPdfDistiller = New PdfDistiller

            Call objPdfDistiller.FileToPDF(strPSFileName, strPDFFileName, "")

             Call Kill(strPSFileName)

         End Sub


不明白为什么不用PDF插件直接生成PDF文档?

追问想在不同的计算机实现以上功能,插件的话需要多安装一个程序。谢谢您,我试一下。

热心网友 时间:2024-01-10 01:59

首先,加载引用,如图

然后,在打印机中对Acrobat Distiller的打印进行设置设置(必须,否则转化出错!)

Public Sub MakePDF(ByVal strPDFFileName As String)

Dim strPSFileName As String

Dim xlWorksheet As Worksheet

Dim objPdfDistiller As PdfDistiller

strPSFileName = Left(strPDFFileName, InStrRev(strPDFFileName, "/")) & "tmpPostScript.ps"

Set xlWorksheet = ActiveSheet

Call xlWorksheet.PrintOut(copies:=1, preview:=False, ActivePrinter:="Acrobat Distiller", printtofile:=True, collate:=True, prtofilename:=strPSFileName)

Set objPdfDistiller = New PdfDistiller

Call objPdfDistiller.FileToPDF(strPSFileName, strPDFFileName, "")

Call Kill(strPSFileName)

End Sub

热心网友 时间:2024-01-10 02:00

Sub test()
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Documents and Settings\Administrator\桌面\test.pdf"
End Sub


EXCEL 2010完美测试通过。PDF默认保存位置为桌面,名字叫TEST,名字路径你可以直接改下。


要发布的工作表也可以改。

热心网友 时间:2024-01-10 02:01

怎样用excel做出PDF文件

热心网友 时间:2024-01-10 02:01

生成PDF不用VBA,EXCEL本身就自带有这个功能,“另存为”——PDF格式,可以通过弹出的保存框中“选项”设置转换属性。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com