Excel 2013 在 VBA 中打印为 PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15030180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel 2013 Print to PDF in VBA
提问by user2100348
As it seems that Excel 2013 allow for direct Save as to PDF format, how can in perform this using VBA code ? I would like to build a macro that will automatically create a PDF from a worksheet (with the name of the file being passed as String variable). Many thanks to you all
由于 Excel 2013 似乎允许直接另存为 PDF 格式,因此如何使用 VBA 代码执行此操作?我想构建一个宏,该宏将自动从工作表创建 PDF(文件名作为 String 变量传递)。非常感谢你们
回答by JustinJDavies
Try
尝试
Dim fp As String
Dim wb As Workbook
fp = "C:\temp\foo.pdf"
Set wb = ActiveWorkbook
wb.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=fp, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
*Note that ExportAFixedFormat
must have all its variables on one line or it will not compile.
**Note that the '_' characters should allow this to compile whilst not being all on one line
*请注意,ExportAFixedFormat
必须在一行中包含所有变量,否则将无法编译。
**请注意,'_' 字符应该允许编译,而不是全部在一行上