1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| Option Explicit
Sub Adjust_Slicers()
Dim sc As SlicerCache, sl As Slicer, slItem As SlicerItem
Dim nCar As Integer, nItem As Integer
For Each sc In ActiveWorkbook.SlicerCaches
For Each sl In sc.Slicers
'Debug.Print sl.Caption, sl.Parent.Name, sl.RowHeight, sl.Height, sl.ColumnWidth, sl.Width
nCar = 0
nItem = 0
For Each slItem In sc.SlicerItems
nItem = nItem + 1
nCar = IIf(Len(slItem.Value) > nCar, Len(slItem.Value), nCar)
'Debug.Print nItem, nCar, slItem.Value
Next
sl.Height = (nItem + 1) * sl.RowHeight * 1.2
sl.Width = 32 + nCar * 4
Next sl
Next sc
End Sub |
Partager