编译错误:子或函数未定义...为什么?

时间:2015-04-28 12:07:52

标签: excel vba pivot

所以这是我的代码应该根据位于同一工作表中的列表循环遍历枢轴的SUPPLIER FILTER。每次循环后,都必须以.pdf格式将文件上传到Intranet。

Sub Upload()
    Dim pt As PivotTable
    Dim pi As PivotItem
    Dim pf As PivotField
    Dim lLoop As Long

    Set pt = Sheets("To Supplier").PivotTables("PivotTable1")
    Set pf = pt.PivotFields("[Query].[SUPPLIER].[SUPPLIER]")

    Sheets("To Supplier").Select

    For Each pi In pf.PivotItems
        On Error Resume Next
        pf.CurrentPage = pi.Value
        On Error GoTo 0
        If pf.CurrentPage = pi.Value Then
            If lLoop = 0 Then
                With Sheets("To Supplier").PageSetup
                    .CenterFooter = pi.Value
                    .LeftHeader = pt.Name
                    .LeftFooter = Now
                End With
            End If
            Range("L2").Select
            ActiveCell.FormulaR1C1 = _
                                    "=INDEX(RC[-6]:R[59]C[-5],MATCH(R[1]C[-10],RC[-6]:R[59]C[-6],0),2)"
                                    Sheets("To Supplier").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                                    "http://collaborationx.com/portalone/sourcing/Supplier%20documents/" & Cell("L2").Value _
                                    & "/Evaluations/" & Cell("L2").Value & "%20Credits.pdf" _
                                    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
                                    :=False, OpenAfterPublish:=True
            lLoop = lLoop + 1
        End If
    Next pi
End Sub

然而,它一直让我失望......现在的问题是,在问题出现在引用之前,它说函数没有定义......

1 个答案:

答案 0 :(得分:0)

Cell("L2")未定义。您可能想要Range("L2"),但是在您使用ActiveCell之前选择了该范围。例如,HTH。

Option Explicit

Sub test()

    Range("L2").Select
    ActiveCell.FormulaR1C1 = "=INDEX(RC[-6]:R[59]C[-5],MATCH(R[1]C[-10],RC[-6]:R[59]C[-6],0),2)"

    Dim exportFileName As String
    exportFileName = "http://collaborationx.com/portalone/sourcing/Supplier%20documents/{0}/Evaluations/{0}%20Credits.pdf"
    exportFileName = Replace(exportFileName, "{0}", ActiveCell.Value)

    Sheets("To Supplier").ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=exportFileName, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True

End Sub