Type Excel.worksheet not defined, Type Excel.workbook not defined

sai_yellow

New member
Joined
May 5, 2010
Messages
3
Programming Experience
Beginner
hi all,
i am new to vb.net programming. i am trying to read an existing excel 2007 file from vb.net i used a form with single button and i written code in button click event code is :
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet

xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Open("C:\Documents and Settings\USER\Desktop\d0805\test1.xlsx")
xlWorkSheet = xlWorkBook.Worksheets("sheet1")
'display the cells value B2
MsgBox(xlWorkSheet.Cells(2, 2).value)
'edit the cell with new value
xlWorkSheet.Cells(2, 2) = "HELLO WORLD"
xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
End Class

i am facing errors saying 1.Type Excel.Application not defined
2. Type Excel.Applicationclass not defined
3.Type Excel.worksheet not defined
4.Type Excel.workbook not defined
please try to help me out.
thanks....
 
Back
Top