You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac版Excel VBA宏二次执行报Run-time error '1004' 求助

Mac版Excel VBA宏打印并保存PDF时反复触发1004错误求助

我在Mac版Excel中编写VBA宏,想要实现打印当前工作表并将其保存为PDF文件的功能,但反复遇到错误:

新建工作簿并另存为启用宏的Book1.xlsm后,编写了如下宏代码:

Sub PrintAndSaveAsPDF()
'Print the active sheet
  ActiveSheet.PrintOut
'Save the active sheet as a .pdf file
  ActiveSheet.ExportAsFixedFormat _
        Type:=0, _
        FileName:="Sheet1.pdf", _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=False
End Sub

该宏首次运行完全正常,既能打印当前工作表,也能在Book1.xlsm所在文件夹生成Sheet1.pdf。但删除生成的Sheet1.pdf后再次运行宏,就会弹出错误提示:

"Run-time error '1004' PrintOut method of Worksheet class failed"

我推测是ExportAsFixedFormat方法阻塞了对默认打印机的访问,已经尝试了网上所有可行的解决建议,但均无法解决问题,恳请帮助。

参考环境:

  • Microsoft Excel for Mac Version 16.72 (23040900)
  • macOS Monterey Version 12.2.1

内容的提问来源于stack exchange,提问作者RL1586

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 08:12:16