vba - 运行时错误 5 - 无效的过程调用或参数

标签 vba excel runtime-error

我需要有关此宏的帮助。每次运行它时,我都会收到以下错误。我认为这是一个简单的宏,我可以让我的团队中的任何人使用它来减少他们每次运行报表时手动创建此数据透视表所需的时间。但是,它不起作用。请参阅下面的错误并提出建议。我将错误加粗并用斜体显示。

Error

Sub LEDOTTR()
'
' LEDOTTR Macro
'

'
    Range("A87").Select
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    ***ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Sheet1!R87C1:R8214C25", Version:=xlPivotTableVersion14).CreatePivotTable _
        TableDestination:="LED OTTR!R1C1", TableName:="PivotTable6", _
        DefaultVersion:=xlPivotTableVersion14***
    Sheets("LED OTTR").Select
    Cells(1, 1).Select
    With ActiveSheet.PivotTables("PivotTable6").PivotFields("LED")
        .Orientation = xlPageField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable6").PivotFields("Hierarchy name")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable6").PivotFields("LED").CurrentPage = "(All)"
    With ActiveSheet.PivotTables("PivotTable6").PivotFields("LED")
        .PivotItems("LED Marine").Visible = False
        .PivotItems("LL48 Linear LED").Visible = False
        .PivotItems("Other").Visible = False
    End With
    ActiveSheet.PivotTables("PivotTable6").PivotFields("LED"). _
        EnableMultiplePageItems = True
    ActiveSheet.PivotTables("PivotTable6").AddDataField ActiveSheet.PivotTables( _
        "PivotTable6").PivotFields("   Late " & Chr(10) & "Indicator"), "Sum of    Late " & Chr(10) & "Indicator", _
        xlSum
    ActiveSheet.PivotTables("PivotTable6").AddDataField ActiveSheet.PivotTables( _
        "PivotTable6").PivotFields("Early /Ontime" & Chr(10) & "   Indicator"), _
        "Sum of Early /Ontime" & Chr(10) & "   Indicator", xlSum
End Sub

最佳答案

您的问题的答案是 located here .

TableDestination:="LED OTTR!R1C1" 中的工作表名称需要用单引号引起来才能正常工作 TableDestination:="'LED OTTR'!R1C1"

如果在重新运行代码之前不删除此数据透视表,您还会遇到重复名称的问题。

关于vba - 运行时错误 5 - 无效的过程调用或参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30538131/

相关文章:

VBA 运行时错误 9 : subscript out of range

excel - "if and"具有两列条件的语句

VB6 应用程序无法在某些计算机上运行,​​但在其他计算机上运行良好

Excel - VBA - 创建每个主键的唯一代码组合

sql - 为什么 ADO 记录集返回的记录多于基础 Access 查询

vba - Excel 宏 : Copy data into new worksheet and sort base on date and random number

mysql - Ruby 创建临时文件来保存 CSV 行并将其分配给数据库

excel vba根据点值更改数据点的条形图颜色

java - 在 voltdb 的存储过程中运行选择查询后出现错误

java - UVA Online Judge 正在返回我找不到的运行时错误