HELP! Need to stop Pivot refreshing with VBA

alemarquezr

New Member
Joined
Sep 15, 2015
Messages
12
Hi all,

I have a file connected to a cube and I created the following code to add Pivot Tables to my slicers automatically BUT every time one pivot is added EXCEL is creating "Running OLAP Query".

PROBLEM: I would like to stop that query and refresh my pivots only when all pivots have been added to all my slicers.

I appreciate your support on this, Thanks!

************************************************************************
Sub ConnectAllSlicerPivots()


Dim MySheet As Worksheet
Dim MyPivot As PivotTable
Dim slCaches As SlicerCaches
Dim slCache As SlicerCache
Dim oSht As Worksheet

Set slCaches = ThisWorkbook.SlicerCaches


For Each slCache In slCaches
For Each MySheet In ActiveWorkbook.Worksheets
For Each MyPivot In MySheet.PivotTables
Debug.Print "To Connect:", MyPivot, "in", slCache.Name
slCache.PivotTables.AddPivotTable MyPivot
Next MyPivot
Next MySheet
Next slCache

MsgBox ("Slicers connected: Graphs Updated")



************************************************************************


BR/ AM
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try:


Code:
With Application
.EnableEvents = False
End With

'Your code

With Application
.EnableEvents = True
End With
 
Upvote 0
Hi Comfy,

It didn't work :S, it seems that pivots force Excel to connect themselves or something but "events" is not freezing the query for each pivot added.
 
Upvote 0
I think I had the wrong setting:

Try:

Code:
With Application
.EnableEvents = False
.Calculation = xlCalculationManual
End With


'Your code


With Application
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With

or add this to your code and update all pivots manually:

Code:
For Each MyPivot In MySheet.PivotTables
Debug.Print "To Connect:", MyPivot, "in", slCache.Name
MyPivot.ManualUpdate = true
slCache.PivotTables.AddPivotTable MyPivot
Next MyPivot
 
Last edited:
Upvote 0
Hi Comfy,

Thanks for your help, with xlCalculationManual you can still see Excel calling "OLAP Query" then if additionally you force manual update for Pivots you still see Excel calling "Running Slicer Operation"

I tried to force my SlicerCache to use the function defined called RequireManualUpdate but I get error :S

Thanks
 
Upvote 0
Yes, I read that post too but by trying now some codes I think that if I make the slicer to stop updating (by using RequireManualUpdate) I can get somewhere.

the issue now is that
RequireManualUpdate is not working for me...
 
Upvote 0

Forum statistics

Threads
1,215,558
Messages
6,125,511
Members
449,236
Latest member
Afua

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top