i cant get selection range from excel. i am using below code block and i can get active sheet like this. but i need only selection range. how can i do this?
Microsoft.Office.Interop.Excel.Application ExApp = Globals.ThisAddIn.Application as Microsoft.Office.Interop.Excel.Application;
Microsoft.Office.Interop.Excel.Worksheet ExWorksheet = ExApp.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet;
Microsoft.Office.Interop.Excel.Range activeSheet = ExWorksheet.UsedRange as Microsoft.Office.Interop.Excel.Range;
thanks for advice.
To select a range of cells, click on the first cell in the range and then drag your mouse over the rest of the cells you want to select. Alternatively, you can click on the first cell in the range and then hold down the Shift key while clicking on the last cell in the range. 2.
When selecting a small range that consists of just a few cells, click the first cell and drag to the last cell you want included in the range. To select a larger range, it's easier to click the first cell and hold down the Shift key while you click the last cell in the range.
The selection is a property of the Application, so you should use something like:
Microsoft.Office.Interop.Excel.Application ExApp = Globals.ThisAddIn.Application as Microsoft.Office.Interop.Excel.Application;
Microsoft.Office.Interop.Excel.Range SelectedRange = ExApp.Selection as Microsoft.Office.Interop.Excel.Range;
Just be careful that the object returned by Selection could be something different fromn a Range (e.g. it could be a Chart), so you should check for null values of SelectedRange.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With