http://support.microsoft.com/kb/318063

http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/60fa78ed-0913-4bf5-9c47-2bc0eea59a2c


   For Each pf In pt.PivotFields
      If pf <> "a" And pf <> "b" And pf.Orientation <> xlHidden Then
         Debug.Print pf
         pf.Orientation = xlHidden
      End If
   Next pf
   For Each pf In pt.DataFields
      Debug.Print pf
      Debug.Print pf.Orientation
   Next pf


  
  
   Set pf = pt.DataFields("Sum of e")
   For Each pi In pf.PivotItems
      pi.Visible = False
   Next pi
  
   For Each pf In pt.DataFields
      Debug.Print pf.SourceName
   Next pf
  
  
  
  
  
   For Each pf In pt.PivotFields
      If pf <> "a" And pf <> "b" And pf.Orientation <> xlHidden Then
         Debug.Print pf
         pf.Orientation = xlHidden
      End If
   Next pf
   For Each pf In pt.DataFields
      Debug.Print pf
      pf.Orientation = xlHidden
   Next pf


Sub RemoveCalculatedFields()
Dim pt As PivotTable
Dim pf As PivotField
Dim pfNew As PivotField
Dim strSource As String
Dim strFormula As String
Set pt = ActiveSheet.PivotTables(1)
    For Each pf In pt.CalculatedFields
        strSource = pf.SourceName
        strFormula = pf.Formula
        pf.Delete
        Set pfNew = pt.CalculatedFields.Add(strSource, strFormula)
    Next pf
End Sub

Option Explicit

Sub test()
   Dim pt As PivotTable
   Dim pf As PivotField
   Dim pfx As PivotField
   Dim pi As PivotItem
   Dim strSource As String
   Dim strFormula As String
  
  
  
  
     
   Set pt = Worksheets("Sheet4").PivotTables("PivotTable1")
  
   For Each pf In pt.DataFields
      If pt.PivotField(pf.SourceName).IsCalculated Then Debug.Print "Assa"
     
     
      Debug.Print pf
      Debug.Print pf.SourceName
      strSource = pf.SourceName
      Debug.Print strSource
   Next pf
  
   Debug.Print pt.p
End Sub

 

 

반응형

+ Recent posts