Problems with the excel find function in vb.net

  • Thread starter Thread starter pp
  • Start date Start date
P

pp

I have copied this code from Excel VBA, to use in a VB.net application:

Dim r as Excel.Range

r=Cells.Find(What:="02/01/2001 22:00:00", After:=ActiveCell,
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)

But in VB.net, the editor doesn’t recognise de following constants:
ActiveCell, xlFormulas, xlPart, xlByRows.

Do you have any ideas?

Thanks,
Paulo Praça
 
Imports Excel = Microsoft.Office.Interop.Excel

Sub Main()
Dim r As Excel.Range

r = Cells.Find( _
What:="02/01/2001 22:00:00", _
, _ <-- Can leave it blank here
LookIn:=Excel.XlFindLookIn.xlFormulas, _
LookAt:=Excel.XlLookAt.xlPart, _
SearchOrder:=Excel.XlSearchOrder.xlByRows, _
SearchDirection:=Excel.XlSearchDirection.xlNext, _
MatchCase:=False, _
SearchFormat:=False)

.....

More info -->
"http://msdn.microsoft.com/office/un...brary/en-us/odc_vsto2003_ta/html/ExcelObj.asp"

HTH,
arunkhemlai
 
Many thanks for your answer. I had a problem with the first line of
code: Imports Excel = Microsoft.Office.Interop.Excel. I have this
answer: Namespace or type ‘Excel’ for the imports
‘Microsoft.Office.Interop.Excel’ cannot be found.

In the begin of my module I have these imports:
Imports Microsoft.Office.Core
Imports System.Data.OleDb

Thanks,
Paulo Praça
 

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

Back
Top