Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 切片器修改属性_Excel_Vba - Fatal编程技术网

Excel 切片器修改属性

Excel 切片器修改属性,excel,vba,Excel,Vba,尝试使用VBA生成透视表和关联切片器。我能够很好地生成表和切片器,但是当我试图修改切片器属性时,我得到了错误5。错误在“With”行中。我现在有什么错 试图将名称值更改为实际切片器装运数量。并在网上四处查看,但我没有看到任何解决方案。我确实从这个网站上找到了一个,但是,当我使用它/键入复制它时,它似乎不起作用 'This works to create slicer ActiveWorkbook.SlicerCaches.Add2(ActiveSheet.PivotTables("MasterP

尝试使用VBA生成透视表和关联切片器。我能够很好地生成表和切片器,但是当我试图修改切片器属性时,我得到了错误5。错误在“With”行中。我现在有什么错

试图将名称值更改为实际切片器装运数量。并在网上四处查看,但我没有看到任何解决方案。我确实从这个网站上找到了一个,但是,当我使用它/键入复制它时,它似乎不起作用

'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

希望代码能够修改显示的切片器,而不会出现任何错误。请,谢谢

切片器。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