通过 VBA 将 MS Excel 2003 工作簿导出为 PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/224301/
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
Exporting an MS Excel 2003 workbook to PDF via VBA
提问by Margaret
I have an Excel 2003 workbook that contains a macro to copy certain of its sheets across to a new workbook, then save and close the new workbook. It does this several dozen times, with slightly different sheet selections each time.
我有一个 Excel 2003 工作簿,其中包含一个宏,用于将其某些工作表复制到新工作簿,然后保存并关闭新工作簿。它这样做了几十次,每次都略有不同的工作表选择。
I would like to add an extra step to the macro to export the secondary workbooks' spreadsheets to PDF. The obvious way to do this would be to use a PDF printer and Excel's built in Print function, but most PDF printers give you a "Save As..." dialogue box before they finish. Obviously, typing this in individually for seventy-odd occasions lacks appeal - so I'd like something that allows me to set it ahead of time (probably "Use the filename of the file I'm printing minus its extension") then just select the default options.
我想向宏添加一个额外的步骤,以将辅助工作簿的电子表格导出为 PDF。显而易见的方法是使用 PDF 打印机和 Excel 的内置打印功能,但大多数 PDF 打印机在完成之前会给您一个“另存为...”对话框。显然,在七十多种情况下单独输入它缺乏吸引力 - 所以我想要一些可以让我提前设置它的东西(可能是“使用我正在打印的文件的文件名减去其扩展名”)然后只需选择默认选项。
Any ideas for a free PDF printer that does this? Or a suitable alternative?
有免费的 PDF 打印机可以做到这一点吗?或者合适的替代品?
回答by Fionnuala
Office 2007 allows for this. I have found PDFCreatorto be good, the VBA is included in sample files, and have heard that CutePDFis also good. PDFCreator and CutePDF are free.
Office 2007 允许这样做。我发现PDFCreator很好,VBA 包含在示例文件中,听说CutePDF也很好。PDFCreator 和CutePDF 是免费的。
回答by Diego Castro
As a development on the (wise) answer from Remou, and since this was what helped me out on my problem too.
作为Remou的(明智的)答案的发展,因为这也帮助我解决了我的问题。
I choose pdfcreator(since I already had it installed) and this is what I ended up using:
我选择pdfcreator(因为我已经安装了它),这就是我最终使用的:
Sub PDF_Print()
Dim p
p = ActivePrinter
ActivePrinter = "PDFCreator"
ActiveDocument.PrintOut
ActivePrinter = p
End Sub
Works like a charm
奇迹般有效
回答by dbb
This may help: http://www.pdf995.com
这可能会有所帮助:http: //www.pdf995.com
One feature is "Three auto-name options to bypass Save As dialog"
一项功能是“绕过另存为对话框的三个自动命名选项”