首" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 如何利用<em>excel</em> VBA生成<em>PDF文件</em&g

如何利用<em>excel</em> VBA生成<em>PDF文件</em&g

作者:乔山办公网日期:

返回目录:excel表格制作


您好,
这里给你提供一个等效的思路:即在调用 ExportAsFixedFormat 方法前把 Excel 文件合并好。

首先,加e799bee5baa6e79fa5e98193e78988e69d83338载引用,如图

然后,在打印机中对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


如果要每个SHEET存一个文件,zd需要循环把每个SHEET先移出来,再另存为PDF。
代码如下,供参考。
Sub 折表存PDF()
Dim MyWork
Dim MySheet
Dim MyPath
MyWork = ActiveWorkbook.Name
MyPath = ActiveWorkbook.Path
For Each MySheet In Sheets
MySheet.Copy
ChDir MyPath
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=MySheet.Name & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
ActiveWindow.Close False
Windows(MyWork).Activate
Next
End Sub

首先,加载引用,如图

然后7a686964616fe59b9ee7ad94362,在打印机中对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

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网