Unknown Error with SlicerCache

wroze27

New Member
Joined
Apr 23, 2021
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
I keep getting the Application-defined or object-defined error when running the code below, the error happens on the highlighted/bolded line.

I do not know enough to understand what I am doing wrong. Can someone please help me walk through how to fix it


VBA Code:
Sub CreateFoldersFromSlicer()

Dim slicer As slicer
Dim slicerCache As slicerCache
Dim slicerItem As slicerItem

Set slicerCache = ActiveWorkbook.SlicerCaches("Slicer_OutSalesPersonName3")
[B][/B]
[U][B]For Each slicerItem In slicerCache.SlicerItem[/B]s[/U]
    If slicerItem.Selected = True Then
        Dim fso As New FileSystemObject
        fso.CreateFolder "my path" & slicerItem.Name
    End If
Next slicerItem
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Dim slicerCache As slicerCache
Dim slicerItem As slicerItem
You should not declare variables with the same name as the object.

Review the changes in the code, some data was missing in your code.

Try this, works for me:
VBA Code:
Sub CreateFoldersFromSlicer()
  Dim myPath As String
  Dim slcr_Cache As slicerCache
  Dim slcr_Item As slicerItem
  Dim fso As New FileSystemObject
  
  myPath = "C:\trabajo\"
  Set slcr_Cache = ActiveWorkbook.SlicerCaches("Slicer_OutSalesPersonName3")
  For Each slcr_Item In slcr_Cache.SlicerItems
    If slcr_Item.Selected = True Then
      fso.CreateFolder myPath & slcr_Item.Name
    End If
  Next slcr_Item
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top