using find in excel from C# code

M

Marc

Hi,

I am working to make an aplication that open an existing excel file, search
for some text and notifies the result. Now, when I run it, before the excel
file's opens get this error:

COMException Types mismatch (Exception HRESULT: 0x80020005
(DISP_E_TYPEMISMATCH))

My code is:

object oMissing = System.Reflection.Missing.Value;

Excel.ApplicationClass oExcel = new Excel.ApplicationClass();
oExcel.Visible = true;
Excel.Workbooks oBooks = oExcel.Workbooks;
Excel._Workbook oBook = null;

oBook = oBooks.Open(path, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing);

Object cad = Cadena.Text;
Object LookIn = "xlValues";
Object LookAt = "xlWhole";

Microsoft.Office.Interop.Excel.XlSearchDirection xlApp = new
Microsoft.Office.Interop.Excel.XlSearchDirection();

Object resultat = oBook.Sheets.Application.Cells.Find(cad,
oMissing, LookIn, LookAt, oMissing, xlApp, oMissing, oMissing,
oMissing).Activate();

// Quit Excel and clean up.

oBook.Close(false, oMissing, oMissing);

System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook);
oBook = null;

System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks);
oBooks = null;
oExcel.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel);
oExcel = null;


Another problem I probably will have is to run the find function for all
sheets.

thanks for advanced.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top