How do I find a value inside an Excel spreadsheet?

Hi all,

I am trying to use the Excel.Range.Find method on a range object in order to find a particular value inside an Excel spreadsheet. However, everytime I execute the find method it throws an exception that says, "Find method of Range class failed." I don't know why this is happening. Here is a snippet of my C# code:

using Excel;

string workbookPath = @"C:\someworkbook.xls";

Excel.Application excelApp = new Excel.ApplicationClass();

excelApp.Visible = true;

Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true);

Excel.Sheets excelSheets = excelWorkbook.Worksheets;

IEnumerator SheetEnumerator = excelSheets.GetEnumerator();

SheetEnumerator.Reset();

SheetEnumerator.MoveNext();

Excel.Worksheet excelWorksheet = (Excel.Worksheet)SheetEnumerator.Current;

Excel.Range SomeCells = excelWorksheet.get_Range("A1", "A10");

Excel.Range FoundCell = SomeCells.Find("Hours Worked", "A1", XlFindLookIn.xlValues, XlLookAt.xlPart, XlSearchOrder.xlByRows, XlSearchDirection.xlNext, false, false);

Does anyone know why the Excel.Range.Find method keeps throwing an exception everytime I execute it Thanks.



Answer this question

How do I find a value inside an Excel spreadsheet?

  • How do I find a value inside an Excel spreadsheet?