update pivot vha VBA
Hej,Jeg vil gerne opdaterer nogle pivottabeller, vha. VBA. Jeg har det meste på plads, men roder helt rundt i definering af dimensioner.
jeg har fx følgende kode:
Private Sub Command10_Click()
DoCmd.Hourglass (-1)
Dim DateSet As Range
Dim PivotDate As Date
Dim TradeDate As Date
Dim pt As PivotTable
Dim pf As PivotFields
'Print Reports
Workbooks.Open FileName:="I:\Risk Management\Automated reports\EGO reports\EOD Credit Exposure\Credit Exposure Clients Report.xlsm"
'picks date from calendar
Form_Control_View.MonthView7.SetFocus
TradeDate = Form_Control_View.MonthView7
Workbooks.Application.Sheets("Summary").Select
'Range("D4").Value = "test"
Set DateSet = Range("F4")
DateSet.Value = TradeDate
savechanges = True
'PivotDate = Sheets("Summary").Range("F4")
PivotDate = TradeDate
Worksheets.Application.Sheets("Summary").Select
Excel.ActiveSheet.PivotTables("PivotTable1").PivotFields("TradeDate").ClearAllFilters
Excel.ActiveSheet.PivotTables("PivotTable1").PivotFields("TradeDate").CurrentPage = PivotDate
ActiveSheet.PivotTables("PivotTable2").PivotFields("TradeDate").ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("TradeDate").CurrentPage = PivotDate
ActiveSheet.PivotTables("PivotTable4").PivotFields("TradeDate").ClearAllFilters
ActiveSheet.PivotTables("PivotTable4").PivotFields("TradeDate").CurrentPage = PivotDate
Worksheets.Application.Sheets("tDKK").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("TradeDate").ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("TradeDate").CurrentPage = PivotDate
ActiveSheet.PivotTables("PivotTable3").PivotFields("TradeDate").ClearAllFilters
ActiveSheet.PivotTables("PivotTable3").PivotFields("TradeDate").CurrentPage = PivotDate
ActiveSheet.PivotTables("PivotTable4").PivotFields("TradeDate").ClearAllFilters
ActiveSheet.PivotTables("PivotTable4").PivotFields("TradeDate").CurrentPage = PivotDate
Worksheets.Application.Sheets("full_List").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("TradeDate").ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("TradeDate").CurrentPage = PivotDate
Worksheets.Application.Sheets("Summary").Select
ActiveWorkbook.Close savechanges = True
DoCmd.Hourglass (0)
End Sub