Fails: ActiveWorkbook.RefreshAll BackgroundQuery:=False

Raysoc

Board Regular
Joined
Feb 10, 2009
Messages
227
Hi there,

I have a few Pivottables in my workbook that are linked to a DB. I am creating a macro to refresh, break the links and delete the pivot tables.

My code works but wont let the Refresh all finish, I read I need to add backgroundquery:= false but when i tried that I get an error:

ActiveWorkbook.RefreshAll BackgroundQuery:=False

Compile Error: Wrong number of arguments or invalid property assignment.

Any ideas as to what the issue is?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
refreshall takes no arguments.
Either
have all the pivotcaches' backgroundquery properties set to False, or
loop through all the workbook's pivotcaches:
Code:
For Each pc In ActiveWorkbook.PivotCaches
 pc.BackgroundQuery = False
  pc.Refresh
Next
this will leave all pivotcaches backgroundquery properties as false. You could retain each one's settings with:
Code:
For Each pc In ActiveWorkbook.PivotCaches
originalBGStatus = pc.BackgroundQuery
  pc.BackgroundQuery = False
  pc.Refresh
  pc.BackgroundQuery = originalBGStatus
Next
(All untested)
 
Upvote 0
this code will ensure data is refreshed before proceeding with the next line of code right?

The reason I tried to enable refreshall with the background clause was because my code was not letting the frefresh finish before proceeding.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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