将多张图纸导出为PDF并获取运行时错误VBA

时间:2019-05-28 04:40:00

标签: excel vba

每次执行宏时,我始终收到'(2147024773)8007007b'的运行时错误,我不知道自己做错了什么。关于如何解决此问题的任何提示?

Dim wsA As Worksheet
Set wsA = ActiveSheet
Sheets("Main_Page").Activate
ActiveSheet.Range("A01:F30").Select
Sheets("Sheet3").Activate
ActiveSheet.Range("A01:B6").Select

Sheets(Array("Sheet1", "Sheet3")).Select

Selection.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & strFilename & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True

End Sub

1 个答案:

答案 0 :(得分:0)

我看不到您创建变量并为其分配值,可以尝试一下。另外,请避免选择和激活。

Sub SaveMultipleSheetsAsPDF()
Dim strFilename As String
Dim sht1 As Range
Dim sht3 As Range

Set sht1 = Worksheets("Main_Page").Range("A1:F30")
Set sht3 = Worksheets("Sheet3").Range("A1:B6")
strFilename = "mySheets"


sht1.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & strFilename & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True

sht3.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & strFilename & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True

End Sub