How to focus a cell in Excel VSTO using C# or to select first cell using C# in VSTO?
Asked
Active
Viewed 2.9k times
15
-
This question has been correctly answered you should mark it as answered. – Anonymous Type Sep 28 '10 at 00:23
-
Refer [this article](http://www.clear-lines.com/blog/post/Excel-extensions-with-VSTO-power-tools.aspx) also – Nov 19 '10 at 05:32
3 Answers
29
Here is one way:
Excel.Worksheet activeSheet = ThisAddIn.ExcelApplication.ActiveSheet;
var range = activeSheet.get_Range("A1", "A1");
range.Select();
ThisAddIn is the name of my test project.

Mikael Svenson
- 39,181
- 7
- 73
- 79
-
1You can also add a reference to Microsoft.Office.Interop.Excel.Extensions; so that you can do var range = activeSheet.Range("A1"); in place of the 2nd line. – Anonymous Type Sep 28 '10 at 00:22
-
8An important thing to note here is that you can only call Select on the active sheet. So if you need to select a cell in something other than the currently active sheet, you'll need to call Activate on it first. – Phred Menyhert Mar 04 '12 at 22:09
3
To select the A2 cell, for example:
Excel.Worksheet Worksheet = excel.ActiveWorkbook.ActiveSheet;
Worksheet.get_Range([1,2], System.Reflection.Missing.Value).Select();

Brad Larson
- 170,088
- 45
- 397
- 571

praveena
- 31
- 1
3
Excel.Application ExcelApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
Excel.Workbook book = ExcelApp.ActiveWorkbook;
Excel.Worksheet sheet = book.ActiveSheet;
Excel.Range ExcelRange = sheet.get_Range("A1");
ExcelRange.Select();

KR Akhil
- 877
- 3
- 15
- 32
-
You realize that was 7 years ago? What does your answer add that is not already in the proposed answers? Explain your solution at least. – Nic3500 Dec 06 '17 at 07:05