Pergunta

I have following issue:
I have a macro which, depending on wether activecell is a part of pivot table or not performs following actions:
- if activecell is not a part of pivot table it creates one with ODBC data source and sql query contained in windows clipboard
- otherwise it replaces PivotCache.CommandText with query contained in clipboard.

This all worked fine until I discovered pivot slicers, once a pivot table is created with macro I am able to add slicer and it works fine, but when I replace CommandText property with new sql query existing slicers do not refresh and as I try to add new one I get error message saying something like this:

"pivot table is created in excel version older than 2007 or compatibility mode"
(I cannot post the message directly because I am not using english version of excel)

I discovered that whenever I change PivotCache.CommandText (or .sql) property programatically PivotCache.Version changes from "xlPivotTableVersion12" to "xlPivotTableVersion2000", which is obviously earlier than Excel 2007. The property .Version is readOnly so I cannot change it.

The problem is that this issue occurs as well in a report widely used in my company where vba is used to construct sql query (based on what user clicked on useform) which is then put to pivot table - and I cannot use slicer.

Does anybody have any idea?

Foi útil?

Solução

Eventually I found some workarounds and learned that this only happens on machines running Polish version on Microsoft Office (checked on multiple machines both Excel 2007 and 2010) and does not happen on English version of Office 2010 (had just one machine for testing).
The worakround is changing from ODBC to OLEDB data source, once changed to OLEDB the issue never happened again.
Some questions asked above (plus why localization matters?) remain unanswered, but I assume this is solved.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top