FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Search in Excel
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM

Search in Excel

Posted: Fri Mar 29, 2013 01:06 PM

Hi,

How can I search a string in an excel-file.
I know how to openen it , write in it, but not how to search in it :cry:
I the string is found, I want to know the column and row.

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM

Re: Search in Excel

Posted: Fri Mar 29, 2013 04:12 PM
Marc

Consider this code :

Rick Lipkin

Code (fw): Select all Collapse
Try
   oEXCEL := TOleAuto():New( "Excel.Application" )
Catch
   Saying := "Error in Opening Excel object"+chr(10)
   Saying += "Make sure you have MS Excel loaded on your Computer"+chr(10)
   MsgInfo( Saying )
      Return(.f.)
End Try

Try
   oExcel:Workbooks:Open( cPATH )  // path and excel file c:\files\yourfile.xls
Catch
   Saying := "Error in Opening Excel Workbook"
   MsgInfo( Saying )
      Return(.f.)
End Try

oBook := oExcel:Get( "ActiveSheet" )
nROWS := oBook:UsedRange:Rows:Count()
nCOLS := oBook:UsedRange:Columns:Count()

FOR nStartRow := nRow to nROWS

        For nCOL := 1 to nCOLS

            xVALUE := oBook:Cells( nStartRow, nCOL):Value

            // test xValue for your string
            // nStartRow and nCOl is the current cell

       Next

Next

oExcel:Quit()
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Search in Excel

Posted: Fri Mar 29, 2013 06:23 PM

There is
oRange:Find( target, ......... )
method available
Please check for this method in VBA online help.
(Open excel and click help )

Regards



G. N. Rao.

Hyderabad, India
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM

Re: Search in Excel

Posted: Fri Mar 29, 2013 06:30 PM
Rick Lipkin wrote:Marc

Consider this code :

Rick Lipkin

 [/code]


Rick,

Thanks for the reply.
Thats how I solved it now,but was looking for a method directly in excel.
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM

Re: Search in Excel

Posted: Fri Mar 29, 2013 06:31 PM
nageswaragunupudi wrote:There is
oRange:Find( target, ......... )
method available
Please check for this method in VBA online help.
(Open excel and click help )


Thanks Roa,

That's where I was looking for.
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite

Continue the discussion