How to deselect a selected chart programatically?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using the excel automation objects (Microsoft.Office.Interop.Excel) for
Office 2003. Using C#.NET I'm retrieving the list of worksheets in a
workbook. For each worksheet, if there is a chart on the worksheet there is a
further processing that is required. However, I need to de-select a selected
chart area (when the mouse is clicked on the chart area the chart and the
data columns get selected). I have used:
foreach(Excel.Chart chart in workbook.Charts)
{
try
{
chart.Deselect();
PageSetup(excelApp, chart);
}
catch(Exception err)
{
PlugInTrace.WriteException(err);
}
}

The above piece of code does not undo the selection of the chart area. Any
help is greatly appreciated.

Thanks.
 
Do you have to select the chart in the first place? Select and activate are
often unnecessary.

To 'deselect' a chart, chart.Deselect should work. A limited test from the
VBE confirmed it worked. But, if it doesn't, select a cell.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
The chart area is already selected and because of that the data columns
associated with the chart are also selected. The code needs to deselect the
chart area, not just the lines on the chart but the entire chart area. The
above code is not doing that. Any suggestions?

Thanks.
 
You cannot select a chart and a worksheet range at the same time.

What needs to be selected? You could try this (translated into C#, of
course):

ActiveChart.Deselect
ActiveSheet.Range("A1").Select

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
Back
Top