首页 > 解决方案 > 在记录的 Pivot 宏上获取运行时错误 5

问题描述

Sub Open_Projects_pivots()

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Open_Project_Details", Version:=6).CreatePivotTable TableDestination:= _
        "Open Projects pivots!R1C1", TableName:="PivotTable1", DefaultVersion:=6
    Sheets("Open Projects pivots").Select
    Cells(1, 1).Select
    With ActiveSheet.PivotTables("PivotTable1")
        .ColumnGrand = True
        .HasAutoFormat = True
        .DisplayErrorString = False
        .DisplayNullString = True
        .EnableDrilldown = True
        .ErrorString = ""
        .MergeLabels = False
        .NullString = ""
        .PageFieldOrder = 2
        .PageFieldWrapCount = 0
        .PreserveFormatting = True
        .RowGrand = True
        .SaveData = True
        .PrintTitles = False
        .RepeatItemsOnEachPrintedPage = True
        .TotalsAnnotation = False
        .CompactRowIndent = 1
        .InGridDropZones = False
        .DisplayFieldCaptions = True
        .DisplayMemberPropertyTooltips = False
        .DisplayContextTooltips = True
        .ShowDrillIndicators = True
        .PrintDrillIndicators = False
        .AllowMultipleFilters = False
        .SortUsingCustomLists = True
        .FieldListSortAscending = False
        .ShowValuesRow = False
        .CalculatedMembersInFilters = False
        .RowAxisLayout xlCompactRow
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotCache
        .RefreshOnFileOpen = False
        .MissingItemsLimit = xlMissingItemsDefault
    End With
    ActiveSheet.PivotTables("PivotTable1").RepeatAllLabels xlRepeatLabels
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Status")
        .Orientation = xlColumnField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Labels")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable1").PivotFields("ShortId"), "Count of ShortId", xlCount
    Range("A1:C4").Select
    Selection.Copy
    Range("A15").Select
    ActiveSheet.Paste
    ActiveSheet.PivotTables("PivotTable2").PivotFields("Labels").Orientation = _
        xlHidden
    With ActiveSheet.PivotTables("PivotTable2").PivotFields( _
        "Requester Team (string)")
        .Orientation = xlRowField
        .Position = 1
    End With
End Sub

我在此代码上收到运行时错误 5,但不确定错误是什么。这是一个录制的宏。仅供参考“Open_Project_Details”是工作表中的动态表“打开项目详细信息”“打开项目枢轴”是目标工作表,将始终保留,此工作表将单击此宏的按钮

标签: excelvba

解决方案


推荐阅读