LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default using find in excel from C# code

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.ReleaseComO bject(oBook);
oBook = null;

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

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oExcel);
oExcel = null;


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

thanks for advanced.

Marc
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write code for find a word in excel? Mx Excel Programming 2 September 18th 07 04:45 AM
How do I find a code in Excel Terranoman Excel Worksheet Functions 4 May 18th 07 02:29 PM
Excel VBA code for find/replace Needles Excel Programming 7 September 19th 06 04:29 PM
Find the cell value in excel by using vb code Michael Excel Discussion (Misc queries) 5 June 14th 05 01:24 PM
How to find the version of Excel in code WayneM Excel Programming 2 September 23rd 03 10:02 PM


All times are GMT +1. The time now is 06:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"