【发布时间】:2021-05-29 15:02:42
【问题描述】:
我正在编写一个将整个工作簿导出为 PDF 文件的宏。
生成过程正常,但现在我想让它在完成后打开新生成的文件。问题是由于文件名不是预定义的,我不能简单地使用它的路径和名称打开它。
我正在使用 PrintOut 方法生成之前选择的 ActivePrinter 为“Microsoft Print to PDF”,或者如果发生错误,则要求用户使用 Application.Dialogs(xlDialogPrinterSetup).Show 手动选择它。
这是这部分的一个sn-p:
Call set_printer
ActiveWorkbook.PrintOut Copies:=1, PrintToFile:=True
... set_printer() 在哪里:
Public Sub set_printer()
On Error GoTo problem_with_pdf_printer
Application.ActivePrinter = "Microsoft Print to PDF"
Done: Exit Sub
problem_with_pdf_printer:
MsgBox "There is a problem with the Microsoft Print to PDF printer." & Chr(13) & Chr(13) & _
"Select another one manually!", vbInformation, "Warning!"
Application.Dialogs(xlDialogPrinterSetup).Show
End Sub
有没有办法在执行该方法后捕获新的文件位置?我想到的另一个想法是自定义“选择文件位置”-对话可以帮助我预定义文件路径,但遗憾的是我不知道如何实现。
非常感谢您,如果您有任何建议和想法,我将非常高兴!
【问题讨论】:
标签: excel vba pdf-generation