首页 > 解决方案 > 为什么更改 Slicercache.TimelineState.SetFilterDateRange 的开始和结束日期会导致“1004”应用程序或对象定义错误?

问题描述

我正在尝试修复以下代码中的 1004 错误。另外,请注意我已经删除了非必要的东西,比如我自己的评论/调试和错误后的其余代码。但我留下了写剧本的人的评论。

背景: 此代码应该做的是为某些数据透视表重置时间段过滤器,这些数据透视表检索会计数据以执行完成百分比计算。但是,几周以来,我们一直收到 1004 错误,并且代码不再运行。

到目前为止的尝试: 那么我尝试/查看了什么来解决这个问题?我尝试传递不同的开始和结束日期值,看看这是否可以解决它,但这并没有帮助。我还检查了缓存已连接到的报告,但这也无助于我理解问题。因为没有任何数据透视表或查询显示任何错误。我剩下的工作最好总结为阅读所有数据透视表并检查论坛是否存在类似问题。

在此先感谢您的帮助。

' This is a subroutine to adjust the selections in the timeline slicers for the pivot data.

    Dim startDate As Date
    Dim endDate As Date
    Dim cache As SlicerCache

' Startdate for all slicers is the min cal date
    startDate = ActiveWorkbook.Sheets("Helpers").Range("MinCalDate").Value

' Set the end date to the last date of this period
    If ActiveWorkbook.Sheets("Helpers").Range("PeriodStart").Value > Date Then
        endDate = DateSerial(Year(Date), Month(Date) + 1, 0)
    Else
        endDate = ActiveWorkbook.Sheets("Helpers").Range("PeriodEnd").Value     
'Set slicer 1 End date as slicer selection instead
    End If

' Transaction dates are between the earlies start date and end date
    Set cache = ActiveWorkbook.SlicerCaches("Timeline_TRANSACTIONDATE")
    
    ActiveWorkbook.SlicerCaches("Timeline_TRANSACTIONDATE").TimelineState.SetFilterDateRange startDate, endDate

.....

End Sub

标签: excelvbapivot-tablepowerqueryexcel-4.0

解决方案


推荐阅读