运行时错误whle exporing范围为pdf
当我试图在PDF文件中输出'sheet'/'range'时,出现运行时错误,无论我将代码保存在表单或不同的模块中,无论我给出的path如何。 我已经尝试了很多代码。 在下面提一下。 我总是得到一个错误。 任何想法为什么?
错误
运行时错误“5”;
无效的过程调用或参数
我试过的代码:
Sub try() Sheets("Sheet1").Range("A1:F10").ExportAsFixedFormat Type:=xlTypePDF, fileName:= _ "c:\Book1.pdf", Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=False End Sub
。
Sub luxation() ThisWorkbook.Sheets("Sheet1").Range("A1:F10").Select Selection.ExportAsFixedFormat _ Type:=xlTypePDF, _ fileName:="temp.pdf", _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False, _ OpenAfterPublish:=True End Sub
。
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
下面的程序将把PDF输出到指定的位置:
'rng - The range you wish to be exported' 'strFP - The file path to save the PDF to' Public Sub fExportPDF(rng As Range, strFP As String) 'Export as PDF With rng .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFP, _ Quality:=xlQualityStandard, IncludeDocProperties:=True, _ IgnorePrintAreas:=False, OpenAfterPublish:=False End With End Sub
要使用该过程,请这样调用它:
Sub SomeProc() fExportPDF ThisWorkbook.Worksheets(1).Range("A1:B3"), "C:\Some Location\example.pdf" End Sub