我对VBA还是很陌生,我正在尝试运行VBA代码以尝试选择切片器,但遇到运行时错误1004 Application Defined或object defined错误。我不确定这是由于名称.SlicerItems引起的,还是代码中是否有其他原因导致这种情况。
Private Sub Workbook_Open()
SVAL = Format(Date, "ww")
SVAL = Format(Date, "YYYY") & SVAL
Sheets("Summary").Select
ActiveWorkbook.RefreshAll
With ActiveWorkbook.SlicerCaches("Slicer_WK_NBR_F")
.ClearManualFilter
For Each oSlicerItem In .SlicerItems
If oSlicerItem.Name = SVAL Then
oSlicerItem.Selected = True
Else
oSlicerItem.Selected = False
End If
Next oSlicerItem
End With
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\brdata\reports\sales\DEPARTMENT_SALES_YTD.xlsx", FileFormat:=51
End Sub
我得到的错误是在上面说的
For Each oSlicerItem in .SlicerItems
任何帮助将不胜感激!