Question

While developing an Excel based application in VSTO, I came across with a problem where I want to trigger standard Excel event handler such as sheetSelectionChanged when certain keys are pressed in combination (ctrl +c).

What I want to achieve is that when a cell is selected in a sheet and "ctrl+c" are pressed, I need to find out which cell is selected and its contents so that I can modify the contents if a certain cell is selected and send the (modified) result of it to clipboard.

In order to find the key combination pressed I am using HOOKS, and I can see during debugging that I can capture it but I am not able proceed from here onwards.

I would appreciate if someone can help me on how can I capture the selected cell address and its contents?

Thanks.

No correct solution

OTHER TIPS

You can use something like this to get the selected cell (or rather range):

var range = Globals.ThisAddIn.Application.Selection as Range;
var value = range.Value2;
var address = range.Address[false, false, Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing];

If only one cell is selected you will get the address like "A15", if you have multiple cells (range) selected you will get the whole range address like "L24:O34". Same with the values, in case of a range you will get a whole array returned.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top