chrisanderson

The cells.find command does not work in my code below. Can anyone

tell me why

Any help much appreciated

Chris Anderson

Public Sub DisplayExcelSheet()

Dim oExcel As New Excel.Application

oExcel = CreateObject("Excel.Application")

'Open the spreadsheet

oExcel.Workbooks.Open("c:\test.xls)

'search for the text

oExcel.Cells.Find(What:="sample text")

end sub



Re: Visual Studio Tools for Office excel cells.find not working

chrisanderson

Oops, the filename is ok ie "c:\test.xls"

i lost the last quotes with cut and paste somehow

Chris Anderson





Re: Visual Studio Tools for Office excel cells.find not working

Steve Hansen

Hi Chris,

Find returns an Excel.Range object representing the first cell it finds that matches your find specs. You should modify your code by adding some statements such as:

Dim rg as Excel.Range

rg = oExcel.Cells.Find(What:="sample text")

' do something with the rg to show that you found it

rg.Select()

If you need to find all of the cells that match what you're looking for, you'll need to use the FindNext method too. Check out the documentation on these methods for the details.

Find:

Here is the interop reference: http://msdn2.microsoft.com/ru-ru/library/microsoft.office.interop.excel.range.find(VS.80).aspx

Here is the VBA reference: http://msdn2.microsoft.com/en-us/library/aa195730(office.11).aspx

FindNext:

Interop reference: http://msdn2.microsoft.com/en-us/library/microsoft.office.interop.excel.range.findnext(VS.80).aspx

VBA reference: http://msdn2.microsoft.com/en-us/library/aa195732(office.11).aspx

Regards,

Steve