How to focus a cell in Excel VSTO using C# or to select first cell开发者_StackOverflow using C# in VSTO?
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.
To select the A2 cell, for example:
Excel.Worksheet Worksheet = excel.ActiveWorkbook.ActiveSheet;
Worksheet.get_Range([1,2], System.Reflection.Missing.Value).Select();
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();
精彩评论