Search in Excel

Search in Excel

Postby Marc Vanzegbroeck » Fri Mar 29, 2013 1: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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Search in Excel

Postby Rick Lipkin » Fri Mar 29, 2013 4:12 pm

Marc

Consider this code :

Rick Lipkin

Code: Select all  Expand view

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()

 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Search in Excel

Postby nageswaragunupudi » Fri Mar 29, 2013 6: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
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Search in Excel

Postby Marc Vanzegbroeck » Fri Mar 29, 2013 6: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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Search in Excel

Postby Marc Vanzegbroeck » Fri Mar 29, 2013 6: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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 107 guests