How to deselect a selected chart programatically?

S

sr152

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.
 
T

Tushar Mehta

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
 
S

sr152

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.
 
J

Jon Peltier

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/
_______
 

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