|
Wednesday,
June 9, 2004
VBA for the "Take Snap Shot Button". It reads the Industry from the Page field then copies the entire sheet. It opens a workbook of snap shot pages. It creates a new page named by the industry, then pastes values and formats. Finally it returns to the live pivot table for more work. This is useful technique to send just the results of a pivot table my mail and not the entire pivot table. It saves space and it is better security.
Sub TakeSnapshot()
' Select the page of the pivotTable.
' ActiveSheet.PivotTables("PivotTable1").PivotFields("Industry Group Name "). _
' CurrentPage = "Banks-Super Regional "
'manually select the Pivot sheet.
' Copy the sheet
'Cells.Select
'Selection.Copy
Dim strIGName As String 'The industry Group Name to name the sheet we create.
Dim wsPivot As Worksheet
Dim strSuffix As String
Set wsPivot = ActiveSheet
strIGName = wsPivot.PivotTables("PivotTable1").PivotFields("Industry Group Name ").CurrentPage
strIGName = Trim(strIGName)
strSuffix = Left(strIGName, 4)
Cells.Copy
'Goto the Snapshop, make new sheet
'Windows("SnapShot.xls").Activate
halActivateSnapShot2 (strSuffix) ' Active or open the Snapshot.xls'
ActiveWindow.WindowState = xlNormal
Sheets.Add
'Paste Values and Formats into new worksheet
Cells.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Cells.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
'Rename the sheet
strIGName = Replace(strIGName, "/", "_")
ActiveSheet.Name = strIGName
'go back to the pivot sheet.
wsPivot.Activate
Application.CutCopyMode = False
End Sub
Sub halActivateSnapShot()
On Error GoTo OpenWorkbook
Windows("SnapShot.xls").Activate
Exit Sub
OpenWorkbook:
Workbooks.Open "Snapshot.xls"
End Sub
Sub halActivateSnapShot2(strSufx As String)
On Error GoTo OpenWorkbook
Dim strWBName As String
strWBName = "SnapShot" & strSufx & ".xls"
Windows(strWBName).Activate
Exit Sub
OpenWorkbook:
On Error GoTo CreateWorkbook
Workbooks.Open strWBName
Exit Sub
CreateWorkbook:
On Error GoTo Oops
Workbooks.Add
ActiveWorkbook.SaveAs strWBName
Exit Sub
Oops:
MsgBox "we shouldn't be here!"
End Sub
|
For questions or comments concerning content on this
website: Stephen Rasey |