Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating an Excel Pivot Table using COM in C# producing 0x800A03EC

I am attempting to create an excel pivot table programatically using the
Excel 12.0 Library. The code I am using is below and I have marked the point
where the error occurs with *******

this.excelApp = new Excel.ApplicationClass();
Excel.Workbook wb = this.excelApp.Workbooks.Add(missing);

Excel.PivotCache pivotCache =
this.excelApp.ActiveWorkbook.PivotCaches().Add(Exc el.XlPivotTableSourceType.xlExternal, missing);
pivotCache.Connection = this.txtConnStr.Text;
pivotCache.MaintainConnection = true;
pivotCache.CommandText = this.txtQuery.Text;
pivotCache.CommandType = Excel.XlCmdType.xlCmdSql;

Excel.Worksheet sheet = (Excel.Worksheet)this.excelApp.ActiveSheet;
Excel.PivotTables pivotTables = (Excel.PivotTables)sheet.PivotTables(missing);

******* ERROR HAPPENS ON NEXT LINE
Excel.PivotTable pivotTable = pivotTables.Add(pivotCache,
this.excelApp.ActiveCell, missing, missing, missing);

pivotTable.SmallGrid = false;
pivotTable.ShowTableStyleRowStripes = true;
pivotTable.TableStyle2 = "PivotStyleLight1";

Excel.PivotField pageField =
(Excel.PivotField)pivotTable.PivotFields("Control" );
pageField.Orientation = Excel.XlPivotFieldOrientation.xlPageField;


It appears that the problem may have to do with the second parameter which
as I understand is the location on the sheet to put the pivot table. I have
tried all variations of the Range object I could think of. Examples of this
I've seen online used Application.ActiveCell which is what I'm using above,
but I always get the same error. The only thing I've been able to find online
references making sure Excel security is set to allow VBA code to run, which
my excel version is. Please help!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I detail Pivot Table data without creating a table (Excel2007) Skeletiko[_2_] Excel Discussion (Misc queries) 1 May 5th 10 08:22 AM
How can I detail Pivot Table data without creating a table (Excel2007) Skeletiko Excel Discussion (Misc queries) 0 May 5th 10 12:21 AM
Excel 2003 Pivot table: creating Fields from Consolidated muti ran Javier Johnson Excel Programming 0 April 8th 09 04:08 PM
Excel 2003 hangs on save after creating pivot table Ed Klein[_2_] Excel Programming 0 January 11th 08 09:54 PM
Chart.Export throws COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC. Steven Excel Programming 1 November 5th 03 07:59 PM


All times are GMT +1. The time now is 04:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"