vba 将工作表模板导出为 PDF 会生成运行时错误 5:过程调用或参数无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14053873/
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 sheet template to PDF generates Runtime Error 5: Invalid Procedure call or argument
提问by Neha
I have created a macro to export the sheet template to PDF:
我创建了一个宏来将工作表模板导出为 PDF:
ActiveWorkbook.Sheets("Sheet2").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ActiveWorkbook.Path & "\Survey Report.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
I tried it other ways but it makes no difference in error.
我尝试了其他方式,但在错误上没有区别。
Links already tried:
已经尝试过的链接:
- http://www.mrexcel.com/forum/excel-questions/608810-printing-multiple-worksheets-pdf-2.html
- http://www.mrexcel.com/forum/microsoft-access/385749-exportasfixedformat-error.html
- http://answers.microsoft.com/en-us/office/forum/office_2010-customize/error-5-invalid-procedure-call-or-argument/574c2c8f-7f2c-4644-9373-bbc14c8d3fd7?msgId=4dbee3f3-ad28-4427-a50b-a3904b09ec1e
- http://www.mrexcel.com/forum/excel-questions/608810-printing-multiple-worksheets-pdf-2.html
- http://www.mrexcel.com/forum/microsoft-access/385749-exportasfixedformat-error.html
- http://answers.microsoft.com/en-us/office/forum/office_2010-customize/error-5-invalid-procedure-call-or-argument/574c2c8f-7f2c-4644-9373-bbc14c8d3fd7?msgId=4dbee3f3- ad28-4427-a50b-a3904b09ec1e
回答by Siddharth Rout
Your actual code works for me. However try this (TRIED AND TESTED)
你的实际代码对我有用。但是试试这个(尝试和测试)
Sub Sample()
ActiveWorkbook.Sheets("Sheet2").Activate
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\Survey Report.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
Note:
注意:
- Also hope
Sheet2
has something in it to print else a blank sheet will give you the error. - If you want to print the sheet from the workbook where you are running the code then you might want to change
ActiveWorkbook
toThisWorkbook
and try again...
- 也希望里面
Sheet2
有一些东西可以打印,否则一张白纸会给你错误。 - 如果要从运行代码的工作簿打印工作表,则可能需要更改
ActiveWorkbook
为ThisWorkbook
并重试...
回答by arunjos007
You also must have Excel's free Microsoft Save as PDF or XPS add-ininstalled.
您还必须安装 Excel 的免费Microsoft Save as PDF 或 XPS 加载项。
回答by spact
I also got this error and tried doing it manually to work out the problem.
我也收到此错误并尝试手动执行以解决问题。
Turns out that you can't save as PDF when the filename (including path) is longer than 218 characters.
事实证明,当文件名(包括路径)超过 218 个字符时,您无法将其另存为 PDF。
回答by deepak
if you have adobe printer installed then just use below code to get a pdf
如果您安装了 adobe 打印机,则只需使用以下代码即可获取 pdf
sub Sample()
ActiveWorkbook.Sheets("Sheet2").Activate
ActiveSheet.Printout
End Sub