Slicer Item name for OLAP data source

Gimics

Board Regular
Joined
Jan 29, 2014
Messages
164
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to create a macro that saves a file using the name of a selected slicer item. My pivot table, though, is connected to an OLAP cube, and I am having troubles pulling the slicer item name.

Right now, I have this:

Code:
Public Sub SaveTables()
Dim GLSlicer As SlicerCache
Dim sFileName As String
Dim SFilePath As String

Set GLSlicer = ThisWorkbook.SlicerCaches("Slicer_Fiscal")
SFilePath = ThisWorkbook.Path & "\"
sFileName = GLSlicer.SlicerItem.Name & ".xlsm"






ThisWorkbook.SaveAs (SFilePath & sFileName)

End Sub

But I get a Run-time error '438': Object doesn't support this property or method.

I think it has something to do with being connected to an OLAP cube; there has to be a way to identify the selected slicer item... any thoughts?
 
Got it!

The loop code I had used from someone else was actually the error! This now works:
Code:
Sub Test()

Dim sC As SlicerCache
Dim sL As SlicerCacheLevel
Dim sI As SlicerItem


Set sC = ThisWorkbook.SlicerCaches("Slicer_Fiscal")
Set sL = sC.SlicerCacheLevels(3)


For Each sI In sL.SlicerItems
Debug.Print sI.Caption
Debug.Print CStr(sI.Value)
Debug.Print sI.Name
Next sI


End Sub
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,217,402
Messages
6,136,413
Members
450,010
Latest member
Doritto305

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