I'm using a small macro to add and delete Data field in pivotable. I have buttom assigned to Buttom, by pushining the buton I can call the field but by pushing twice it should be hidden, but it doesnt happend. One of the reason, pointed to Set myshape = ActiveSheet.Shapes(Application.Caller). Maybe I have another problems with code. Here's the code:
Sub Base_Salary()
Dim pt As PivotTable
Dim pf As PivotField
Dim sField As String
Dim myshape As Shape
Set pt = ActiveSheet.PivotTables(1)
Set myshape = ActiveSheet.Shapes(Application.Caller)
sField = myshape.TextFrame.Characters.Text
If pt.PivotFields(sField).Orientation = xlDataField Then
pt.PivotFields(sField).Orientation = xlHidden
myshape.Fill.ForeColor.Brightness = 0.5
Else
pt.PivotFields(sField).Orientation = xlDataField
myshape.Fill.ForeColor.Brightness = 0
End If
End Sub