Excel 2003 and VB 2005

akalmand

Member
Joined
Jul 12, 2007
Messages
8
Programming Experience
Beginner
Dim xlapp As New Microsoft.Office.Interop.Excel.Application
Dim wrkbook As Microsoft.Office.Interop.Excel.Workbook
Dim wrksheet As Microsoft.Office.Interop.Excel.Worksheet

xlapp.Visible = True
wrkbook = xlapp.Workbooks.Open("some path\abc.xls")
wrksheet = wrkbook.Sheets("Sheet1")
wrksheet.Cells.Find(What:="Rotor", After:=Cells(1, 1), LookIn:=xlValues, MatchCase:=False).Activate()
==========================================================

Hi Guys,

In the above code, i am trying to open an excel sheet and look for different names to see if they are in the sheet...

this code works fine in VBA when written for excel in macros but not working for vb.net

The problem I am having is that for the find function, Cells, xlValues, intellisense says that Cells and xlValues are not declared


Am I supposed to add some add ins or some library to be included for intellisense to accept the syntax of this function..

Please suggest....

thanks
 
This Imports is very useful when working with all those namespaces:
VB.NET:
Imports Excel = Microsoft.Office.Interop.Excel
Your Cells(1,1) is most likely wrksheet.Cells(1,1). This is also the default cell to start search in and the parameter is optional so you can leave it out.

xlValues is a member of the XlFindLookIn enumeration, access it like this: Excel.XlFindLookIn.xlValues
 
Subsituting an enumeration value with an arbitrary integer value is not a good idea, the library may define it one way, the interop or other wrapper another. xlWhole is part of the XlLookAt enumeration, same as described above you would use the value Excel.XlLookAt.xlWhole.
 
Back
Top