VBA Error9导出为pdf

时间:2015-05-21 14:51:49

标签: excel vba excel-vba pdf subscript

使用Excel VBA,我尝试以PDF格式打印一张工作簿。

我正在使用此代码:

    Private Sub cmd_Print_Design_Click()

    Sheets("Sheet1").ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=ThisWorkbook.Path & "/" & "Design Summary", _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True

    End Sub

代码没有运行,我得到ERROR 9 "Subscript out of Range"。我无法理解如何解决它。

1 个答案:

答案 0 :(得分:1)

在Windows下,路径分隔符是反斜杠\,因此请更改以下代码行:

Filename:=ThisWorkbook.Path & "/" & "Design Summary",

Filename:=ThisWorkbook.Path & "\" & "Design Summary",