Get Excel Selected Range via VSTO with C#

These days I have been working on the development of an Excel Add-in and learnt a way to get the currently selected range in Excel.
Take it for example that your Project namespace is ExcelAddIn. Firstly, you should refer the interop by following code:

using Microsoft.Office.Interop.Excel;

and you can get a string consistent with the Range you selected by following code:

ExcelAddIn.Globals.ThisAddIn.Application.Selection.Address;

which would return a string in format like “$A$1:$B$2″ for rectangles,”$1:$2” for rows and “$A:$B” for columns.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.