View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
[email protected] beancurdjelly2003@yahoo.com.hk is offline
external usenet poster
 
Posts: 35
Default macro on pivot tables / pivot items

On 5$B7n(B8$BF|(B, $Be8a(B2$B;~(B49$BJ,(B, wrote:
On 5$B7n(B8$BF|(B, $Be8a(B2$B;~(B18$BJ,(B, "Bernie Deitrick" <deitbe @ consumer dot org wrote:





Try this:


Sub PrintPTMacro()
Dim i As Integer
Dim j As Integer
Dim myB As Workbook


With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Name")
For i = 1 To .PivotItems.Count
.PivotItems(i).Visible = True
For j = 1 To .PivotItems.Count
If j < i Then .PivotItems(j).Visible = False
Next j
ActiveSheet.Cells.Copy
Set myB = Workbooks.Add
myB.Sheets(1).Cells.PasteSpecial xlPasteValues
myB.Sheets(1).Cells.PasteSpecial xlPasteFormats
myB.SaveAs ThisWorkbook.Path & "\" & .PivotItems(i).Name & ".xls"
MsgBox .PivotItems(i).Name & " has been saved to a new file"
myB.Close False
Next i
End With
End Sub


--
HTH,
Bernie
MS Excel MVP


wrote in message


...


On 5$B7n(B5$BF|(B, $B2<8a(B10$B;~(B37$BJ,(B, "Bernie Deitrick" <deitbe @ consumer dot org
wrote:
Try this one...


HTH,
Bernie
MS Excel MVP


Sub SavePTMacro()
Dim i As Integer
Dim j As Integer
Dim myB As Workbook


With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Name")
For i = 1 To .PivotItems.Count
.PivotItems(i).Visible = True
For j = 1 To .PivotItems.Count
If j < i Then .PivotItems(j).Visible = False
Next j
ActiveSheet.Cells.Copy
Set myB = Workbooks.Add
myB.Sheets(1).Cells.PasteSpecial xlPasteValues
myB.SaveAs ThisWorkbook.Path & "\" & .PivotItems(i).Name & ".xls"
MsgBox .PivotItems(i).Name & " has been saved to a new file"
myB.Close
Next i
End With
End Sub


wrote in message


...


Hi,


If I want to save as file instead of print out? How can I do it?


Thanks!- $Bp,i6Ho0zMQJ8;z(B -


- $Bp}<(Ho0zMQJ8;z(B -
Thanks Bernie. It work, but only save one file then show run time
error 1004....


How can same format on Pivottable1 (color, font... ...) when split out
the pivot item?- $Bp,i6Ho0zMQJ8;z(B -


- $Bp}<(Ho0zMQJ8;z(B -


Hi,

Still show error message 1004 when success to split out on the first of PivotField
name....(only success save 1 file)
But the format are ok, how the split out file need the drill data?
How can i do? Can I run the Pivot Table's name (Sheet name) instead of PivotTable1?