How to find existing ChartObject in a worksheet?
My goal is to reuse the chartobject in a given sheet (ws).
int iCount = ws.ChartObjects.Count; Excel.ChartObject myChartObject; if( iCount 0) { myChartObject = (Excel.ChartObject)ws.ChartObjects(iCount); } else { Excel.ChartObjects chartObjects = (Excel.ChartObjects)ws.ChartObjects(missing); myChartObject = chartObjects.Add(100, 100, 400, 300); } .... But this code couldn't compile due to: Microsoft.Office.Interop.Excel._Worksheet.ChartObj ects(object)' is a 'method', which is not valid in the given context How could we detect if the existing ChartObject in a sheet? Could any one help? Thanks in advance for any hint. --PD |
How to find existing ChartObject in a worksheet?
On Feb 8, 9:22 am, "itdept" wrote:
My goal is to reuse the chartobject in a given sheet (ws). int iCount = ws.ChartObjects.Count; Excel.ChartObject myChartObject; if( iCount 0) { myChartObject = (Excel.ChartObject)ws.ChartObjects(iCount);} else { Excel.ChartObjects chartObjects = (Excel.ChartObjects)ws.ChartObjects(missing); myChartObject = chartObjects.Add(100, 100, 400, 300);} ... But this code couldn't compile due to: Microsoft.Office.Interop.Excel._Worksheet.ChartObj ects(object)' is a 'method', which is not valid in the given context How could we detect if the existing ChartObject in a sheet? Could any one help? Thanks in advance for any hint. --PD Found solution: Excel.ChartObjects chartObjects = (Excel.ChartObjects) ws.ChartObjects(missing); int iCount = chartObjects.Count; Excel.ChartObject myChartObject; if (iCount 0) myChartObject = chartObjects(iCount); else myChartObject = chartObjects.Add(...) ... |
All times are GMT +1. The time now is 03:36 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com