views:

664

answers:

1

Hi, I'm trying to write a VBA script that will draw buttons beside the PageFields in a Pivot Table, these buttons will loop through the values in the PageField. I had this working for a regular Pivot Table, but I've been asked to adapt it for an OLAP Cube (External Data Source) and I can't work out how to find the values for a Member using VBA (for an OLAP Cube).

Can anyone help?

Previously I had the following

Public Function Next_page(row)
Dim pivTable As PivotTable
Dim pgField As PivotField

Set pivTable = ActiveSheet.PivotTables(1)
For Each pgField In pivTable.PageFields
    If pgField.DataRange.row = CInt(row) Then
        If pgField.CurrentPage.Name = "(All)" Then
            If pgField.PivotItems.Count > 0 Then
                pgField.CurrentPage = pgField.PivotItems(1).Name
            End If
            Exit Function
        End If
        For j = 1 To pgField.PivotItems.Count Step 1
            If pgField.PivotItems(j) = pgField.CurrentPage.Name Then
                If (j < pgField.PivotItems.Count) Then
                    pgField.CurrentPage = pgField.PivotItems(j + 1).Name
                    Exit Function
                End If
            End If
        Next j
        Exit Function
    End If
Next

End Function

But because the CurrentPage doesn't exist for an OLAP Cube it doesn't work.

A: 

This MSDN Link (Extending OLAP Functionality) has quite a few VBA code snippets showing how to use the pivot table API.

ConcernedOfTunbridgeWells