3

I am creating a excel Add-in using visual studio 2010. I was able to get the cell address using this code.

label1.Label = Globals.MyAddIn.Application.ActiveCell.Address.ToString();

I want to get the cell value. Also if you can tell me how to set a value for a given cell.

Please help.

1 Answer 1

5

to get a cell value for the active cell the following should do it

var cellValue = Globals.MyAddIn.Application.ActiveCell.Value.ToString()

or for a specific cell

var cellValue = Globals.MyAddIn.Application.Cells("A1").Value.ToString()

To Set the value it is basically the reverse

Globals.MyAddIn.Application.Cells("A1").Value = "ABC123"

EDIT
Try this. I know that this works as I have something like it working in my own addin.

int row = 1;
int col = 1;
var sheet1 = (Excel.Worksheet)Application.ActiveWorkbook.Worksheets["Sheet1"];
sheet1.Cells[row, col] = "ABC123";

string cellValue = sheet1.Cells[row,col];
2
  • but can't set a value Error 1 Non-invocable member 'Microsoft.Office.Interop.Excel._Application.Cells' cannot be used like a method. Please help Commented Apr 6, 2011 at 4:27
  • 1
    also can't take specific cell value {var cellValue = Globals.MyAddIn.Application.Cells("A1").Value.ToString()} Commented Apr 6, 2011 at 4:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.