gpt4 book ai didi

excel - 切片器修改属性

转载 作者:行者123 更新时间:2023-12-04 22:26:59 24 4
gpt4 key购买 nike

尝试使用 VBA 生成数据透视表和关联的切片器。我能够很好地生成表格和切片器,但是当我尝试修改切片器属性时出现错误 5。错误出现在“With”行中。我目前有什么问题?

尝试将名称值更改为实际的 Slicer_ShipQuantity。并在网上四处寻找,但我没有看到任何解决方案。我确实找到的是来自这个网站,https://www.microsoft.com/en-us/microsoft-365/blog/2011/01/27/control-slicers-by-using-vba/但是,当我使用它/键入复制它时,这似乎不起作用。

'This works to create slicer
ActiveWorkbook.SlicerCaches.Add2(ActiveSheet.PivotTables("MasterPivot"), "ShipQuantity") _
.Slicers.Add ActiveSheet, , "ShipQuantity", "ShipQuantity", _
RowLocation, ColumnLocation, width, Height

'this does not work to modify slicer settings. And I have no idea why.
With ActiveWorkbook.SlicerCaches("ShipQuantity").Slicers("ShipQuantity")
.NumberOfColumns = 3
.RowHeight = 13
.ColumnWidth = 70
End With

期望得到代码修改显示的切片器,而不会出现任何错误。请和谢谢!

最佳答案

Slicers.Add返回对添加的切片器的引用,因此您可以直接使用该引用

https://docs.microsoft.com/en-us/office/vba/api/excel.slicers.add

Dim slcr

Set slcr = ActiveWorkbook.SlicerCaches.Add2(ActiveSheet.PivotTables("MasterPivot"), "ShipQuantity") _
.Slicers.Add(ActiveSheet, , "ShipQuantity", "ShipQuantity", _
RowLocation, ColumnLocation, width, Height)


With slcr
.NumberOfColumns = 3
.RowHeight = 13
.ColumnWidth = 70
End With

关于excel - 切片器修改属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56957444/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com