Pivot Table Issues

Refresh an OLAP PivotTable with VBA in WPS Office Spreadsheets

Steve KSteve K Nov 13, 2026 869 views

Question details

The user needs to refresh an OLAP PivotTable through VBA and remove stale items, without using the PivotCache clearing method that works for standard PivotTables.

Refresh an OLAP PivotTable with VBA in WPS Office Spreadsheets
Product
WPS Office Spreadsheets
Device & OS
not provided
Scenario
The user has existing VBA that sets MissingItemsLimit and refreshes PivotCaches. It works for standard PivotTables but errors on an OLAP PivotTable, so they need a reliable way to refresh connected OLAP data.
Observed behavior
The standard VBA approach that clears or refreshes the workbook PivotCache causes an error when applied to an OLAP PivotTable.
Before you start

Confirm that the OLAP PivotTable is connected to an accessible external data source and that you have permissions to refresh it. Open the workbook in WPS Office Spreadsheets and enable VBA macros if prompted.

Solution 1Recommended

Refresh an OLAP PivotTable with VBA Using SourceType and RefreshTable

Use this solution when you want to automate the refresh of externally sourced PivotTables and avoid the cache-clearing code that fails with OLAP data sources.

OLAP PivotTables retrieve data directly from an external source such as an Analysis Services cube, so they do not use the workbook cache in the same way as standard PivotTables. Instead of clearing PivotCaches, check the SourceType property and call RefreshTable only for external PivotTables.

Use the Workbook_Open procedure to refresh all external PivotTables whenever the workbook opens, or adapt the code to run from a macro button. The refresh still requires access, authentication, and permissions for the OLAP data source.

1
Open the VBA editor

In WPS Office Spreadsheets, click the Developer tab and then click View Code, or press Alt+F11 to open the VBA editor.

2
Add the refresh macro

In the Project Explorer, double-click ThisWorkbook, paste the macro, and confirm it loops through ActiveWorkbook.Worksheets and each worksheet PivotTables collection.

3
Check for external sources

Inside the loop, use If xPt.SourceType = xlExternal Then xPt.RefreshTable to refresh only externally sourced OLAP PivotTables.

4
Save and run

Save the workbook in a macro-enabled format, then reopen it to run the Workbook_Open refresh or run the macro manually from the Developer tab.

Refresh an OLAP PivotTable with VBA Using SourceType and RefreshTable
Cache cleared by refresh: The macro refreshes the OLAP PivotTable directly from its data source without calling PivotCache clearing methods that cause errors.
Direct solution in WPS Spreadsheets

Refresh OLAP PivotTables Automatically with WPS Office Spreadsheets VBA

Use the built-in VBA editor in WPS Office Spreadsheets to loop through externally sourced PivotTables and call RefreshTable directly, avoiding the workbook cache methods that fail with OLAP data sources.

  1. 1. Enable macros: Open WPS Office Spreadsheets and enable macros from the Developer tab or trust center settings.
  2. 2. Open the VBA editor: Press Alt+F11 to open the VBA editor and double-click ThisWorkbook in the Project Explorer.
  3. 3. Insert the refresh code: Paste the Workbook_Open code that loops through worksheets and refreshes each PivotTable where SourceType equals xlExternal.
  4. 4. Run or reopen the workbook: Save the workbook in a macro-enabled format, then reopen it to run the refresh automatically or run the macro manually.
Automates OLAP PivotTable refresh without clearing workbook cachesUses familiar Excel-compatible VBA properties such as SourceType and RefreshTableMaintains compatibility with Microsoft Excel .xls, .xlsx, and macro-enabled .xlsm workbooksProvides a free, lightweight WPS Office environment for editing and running workbook macros
microsoft office alternative - wps office

Frequently Asked Questions

Why does clearing PivotCaches fail for an OLAP PivotTable?

OLAP PivotTables connect directly to an external cube or Analysis Services source rather than storing all source data in the workbook cache. Use the SourceType and RefreshTable approach instead of clearing the cache.

How can I identify an externally sourced PivotTable in VBA?

Check the PivotTable.SourceType property. For OLAP and other external PivotTables, SourceType returns xlExternal, so you can conditionally call RefreshTable.

Does refreshing an OLAP PivotTable require extra permissions?

Yes. You need access to the OLAP data source, valid authentication, and permissions to query or refresh the cube. The refresh will fail if the connection is unavailable.

Can I run this VBA refresh in WPS Office Spreadsheets?

Yes. WPS Office Spreadsheets supports VBA macro editing. Open the VBA editor, add the macro to ThisWorkbook, and save the workbook in a macro-enabled format.

What should I do if stale OLAP items still appear after refreshing?

If RefreshTable succeeds but stale items remain, check the OLAP cube, dimension, or measure group configuration on the server, and make sure the connection points to the updated database or analysis database.