VSTO - How to find all Pivot tables in the Workbook

S

Smugliy

Hi ,
I have seen a lot of examples how to find pivot tables using macro.
But in C# I don't have Count property

for (int i = 1; i <= this.Application.Sheets.Count; i++)
{
Excel.Worksheet ws =
(Excel.Worksheet)this.Application.Sheets;
for (int j = 1; j<= ws.PivotTables.Count // ERROR

How can I do it in C#?
Thanks a lot
Smugliy
 
J

Jon Peltier

Does this part work?

this.Application.Sheets.Count

I would have done something like
this.Application.ActiveWorkbook.WorkSheets.Count, but I can't pretend to
know how VSTO works. It's a matter of referencing more specifically. If you
ask how many pivot tables are on a chart sheet, you'll get an error.

- Jon
 
S

Smugliy

I found it if somebody interested


Excel.PivotTables pivotTables1 =
(Excel.PivotTables)ws.PivotTables(Type.Missing);

if (pivotTables1.Count > 0)
{
for (int j = 1; j <= pivotTables1.Count; j++)
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top