View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Derek Bliss[_2_] Derek Bliss[_2_] is offline
external usenet poster
 
Posts: 7
Default Personal.xls macro that writes to ThisWorkBook

I've writen a macro that only runs when my user needs to run the marco. Here
is what the marco does:
1) User opens a SAP report which needs to be formated.
2) User runs my macro to format the report
3) Macro also creats a PivotTable on worksheet "Discounts".
4) User might need to update one of the fields in Data worksheet and
if the user wants to have the PivotTable updated, they have to click on
the
PivotTable and then Refresh the data.

Here is what I would like to do:
I would like it so that when the macro runs, it would put some code in the
"ThisWorkbook" that will do the following :
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim DisSheet, CurSheet
DisSheet = "Discounts"
CurSheet = ActiveCell.Worksheet.Name
If CurSheet = DisSheet Then GoTo 10
If CurSheet < DisSheet Then GoTo 20
10: Sheets("Discounts").Select
Range("A3").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache. Refresh
20:
End Sub

How do I do this by adding it to my Macro in my Personal.xls file?

I should also add that the SAP report file is going to be new each time so
it not like the same file will be used each time.

Derek