在 Workbook_BeforePrint 内启用导出为 pdf 取消

Enable export as pdf inside Workbook_BeforePrint Cancel

我的 "Workbook_BeforePrint(Cancel As Boolean)" 似乎阻止我导出为 PDF。我发现如果我删除这个子,PDF 导出工作,但我想在打印之前保留我的 "fixes"。

有没有办法重写我的代码以处理导出为 pdf 的问题?

A) 在导出时忽略 "Before print cancel"(对 PDF 无后效)

B) 使代码适用于导出,保留我的代码添加的后效果

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Application.Volatile True
    Cancel = True

    Application.EnableEvents = False
    Application.ScreenUpdating = False

   'My code

    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub

ActivePrinter 显示当前打印机名称(类似于 Canon MP230 series auf Ne03:)。导出为 pdf 时,活动打印机会相应更改(在我当前的站点:Foxit Reader PDF Printer auf Ne01:)。

假设您的 pdf 打印机是 foxit,您可以使用以下代码:

...
if (Left(ActivePrinter, 5) <> "Foxit") then
    'regular printing, therefore execute your code
else
    'pdf-priner, therefore do something else (or nothing)
end if
...