Excel:VBA打印到PDF - 运行时错误1004 [英] Excel: VBA to print to PDF - Run time error 1004

查看:845
本文介绍了Excel:VBA打印到PDF - 运行时错误1004的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试使用以下解决方案从Excel打印到PDF:

I have tried using the following solution to print from Excel to PDF:

Excel 2013在VBA中打印到PDF

虽然该解决方案似乎适用于其他人,在我的情况下会产生运行时错误1004。有没有人有什么进一步的想法,为什么这可能是?我已经搜索了一下,仍然无法弄清楚原因是什么?可能是我的Excel版本不一样(我使用2007)?

While the solution seems to have worked for other people, it produces a run time error 1004 in my case. Does anyone have any further ideas as to why this may be? I have searched aroudn and still cannot figure out what the reason might be? Could it be that my version of Excel is different (I use 2007)?

我原来的解决方案所做的唯一的mod就是改变文件路径,以便保存到我的桌面我的代码如下:

The only mod I made to the original solution was to change the file path so it would save to my desktop. My code is the following:

Sub Invoice_to_PFD()
      'Saves the invoice print area to a PDF file

       Dim fp As String
       Dim wb As Workbook

       fp = "C:\desktop\NewInvoice.pdf"
       Set wb = ActiveWorkbook

       wb.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fp, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

End Sub


推荐答案

所以这是Windows用户现在的工作代码(Mac OS可能需要调整文件路径):

So this is the working code now for Windows users (Mac OS might have to adjust file path):

Sub Invoice_to_PDF()
'Saves the invoice print area to a PDF file

Dim fp As String
Dim wb As Workbook
Dim ws As Worksheet

fp = "C:\Users\[username]\Desktop\NewInvoice.pdf"
Set wb = ActiveWorkbook
Set ws = Worksheets("Invoice")

ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fp, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True


End Sub

这篇关于Excel:VBA打印到PDF - 运行时错误1004的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆