none
non-invocable member '_worksheet.range object object ' cannot be used like a method RRS feed

  • Question

  • I am trying to write code using C# to append some data in excel file in the last empty row but i get error in the last line of code concerned with range saying "non-invocable member '_worksheet.range object object ' cannot be used like a method"

    my code:

    Excel.Application excelapp = new Excel.Application();
                  Excel.Workbook`enter code here` excelbook;
                  string path = "mypath";
                  excelbook = excelapp.Workbooks.Open(path, 0, False, 
                  5,System.Reflection.Missing.Value, 
                  System.Reflection.Missing.Value,False, 
                  System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value,True, False, 
                   System.Reflection.Missing.Value, False);
    
                Excel.Sheets excelsheets = excelbook.Sheets;
                Excel.Worksheet excelsheet = excelsheets[1];
                Excel.Range range = excelsheet.UsedRange;
    
              range.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Activate();
    
                Int32 newrow = excelapp.ActiveCell.Row + 1;
                string newcelladdress = "A"  +newrow;
    
               // The Error is here underline .Range
                excelsheet.Range(newcelladdress).Value = "New Data";

    Sunday, September 30, 2018 11:00 PM

Answers

  • I think you need brackets, not parenthesis (square, not round).

    excelsheet.Range[newcelladdress].Value = "New Data";

    Monday, October 1, 2018 2:31 AM

All replies