Kevin Boyd
Kevin Boyd

Reputation: 12379

How to generate a cell click event in Excel 2007 VSTO with VB?

Well I have browsed through Application events in Excel 2007 however I can't find any event generated on a cell click.
I can't use a double click event at the moment due to application constraints.
Is there a way I can create a custom click event and attach it to a sheet for generating a cell click event.

Upvotes: 4

Views: 3746

Answers (1)

Mathias
Mathias

Reputation: 15391

You should be able to capture that through the Worksheet.SelectionChange event, as illustrated in the snippet below. If you are interested in single cells, you may have to make sure that the range is a single cell.

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
   var sheet = this.Application.ActiveSheet as Excel.Worksheet;
   sheet.SelectionChange += new Excel.DocEvents_SelectionChangeEventHandler(sheet_SelectionChange);
}

void sheet_SelectionChange(Excel.Range Target)
{
   MessageBox.Show("Changed!");
}

Upvotes: 3

Related Questions