Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Read Excel File

Read Excel File

Scheduled Pinned Locked Moved Visual Basic
debuggingcsharpgraphicssysadmin
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rupeshkp728
    wrote on last edited by
    #1

    I want to read excel sheet cells. I have written the following code in Visual Basic 2005 in single desktop environment with no net connectivity:

    Public Class Form1

    Public xl As New Excel.Application
    Public xlsheet As Excel.Worksheet
    Public xlwbook As Excel.Workbook
    Public j As Integer
    
    Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("Hello")
    
        xlwbook = xl.Workbooks.Open("D:\\sample.xls")
        xlsheet = xlwbook.Sheets.Item(1)
    
        TextBox1.Text = xlsheet.Cells(2, 1) ' row 2 col 1
        TextBox2.Text = xlsheet.Cells(2, 2) ' row 2 col 2 
    
    
        xl.ActiveWorkbook.Close(False, "D:\\sample.xls")
        xl.Quit()
    End Sub
    

    End Class

    I am getting the errors as: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Vbc.exe /noconfig /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Data,System.Drawing,System.Diagnostics,System.Windows.Forms /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 /rootnamespace:VBCheck /doc:obj\Debug\VBCheck.xml /define:"CONFIG=\"Debug\",DEBUG=-1,TRACE=-1,_MyType=\"WindowsForms\",PLATFORM=\"AnyCPU\"" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /main:VBCheck.My.MyApplication /debug+ /debug:full /out:obj\Debug\VBCheck.exe /resource:obj\Debug\VBCheck.Form1.resources /resource:obj\Debug\VBCheck.Resources.resources /target:winexe Form1.vb Form1.Designer.vb "My Project\AssemblyInfo.vb" "My Project\Application.Designer.vb" "My Project\Resources.Designer.vb" "My Project\Settings.Designer.vb" error BC30002: Type 'Excel.Application' is not defined. error BC30002: Type 'Excel.Worksheet' is not defined. error BC30002: Type 'Excel.Workbook' is not defined. How to get rid of this error?

    S R A 3 Replies Last reply
    0
    • R rupeshkp728

      I want to read excel sheet cells. I have written the following code in Visual Basic 2005 in single desktop environment with no net connectivity:

      Public Class Form1

      Public xl As New Excel.Application
      Public xlsheet As Excel.Worksheet
      Public xlwbook As Excel.Workbook
      Public j As Integer
      
      Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          MsgBox("Hello")
      
          xlwbook = xl.Workbooks.Open("D:\\sample.xls")
          xlsheet = xlwbook.Sheets.Item(1)
      
          TextBox1.Text = xlsheet.Cells(2, 1) ' row 2 col 1
          TextBox2.Text = xlsheet.Cells(2, 2) ' row 2 col 2 
      
      
          xl.ActiveWorkbook.Close(False, "D:\\sample.xls")
          xl.Quit()
      End Sub
      

      End Class

      I am getting the errors as: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Vbc.exe /noconfig /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Data,System.Drawing,System.Diagnostics,System.Windows.Forms /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 /rootnamespace:VBCheck /doc:obj\Debug\VBCheck.xml /define:"CONFIG=\"Debug\",DEBUG=-1,TRACE=-1,_MyType=\"WindowsForms\",PLATFORM=\"AnyCPU\"" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /main:VBCheck.My.MyApplication /debug+ /debug:full /out:obj\Debug\VBCheck.exe /resource:obj\Debug\VBCheck.Form1.resources /resource:obj\Debug\VBCheck.Resources.resources /target:winexe Form1.vb Form1.Designer.vb "My Project\AssemblyInfo.vb" "My Project\Application.Designer.vb" "My Project\Resources.Designer.vb" "My Project\Settings.Designer.vb" error BC30002: Type 'Excel.Application' is not defined. error BC30002: Type 'Excel.Worksheet' is not defined. error BC30002: Type 'Excel.Workbook' is not defined. How to get rid of this error?

      S Offline
      S Offline
      Simon_Whale
      wrote on last edited by
      #2

      This sounds like you haven't referenced the Microsoft Excel Object Library. Have a read of this MS help and support Article: How to automate Excel from Visual Basic .NET to fill or to obtain data in a range by using arrays [^] I know the article is about arrays but the principle of connecting to excel is the same

      Nagy Vilmos wrote:

      And eat bacon. Bacon's real important for 'puters.

      1 Reply Last reply
      0
      • R rupeshkp728

        I want to read excel sheet cells. I have written the following code in Visual Basic 2005 in single desktop environment with no net connectivity:

        Public Class Form1

        Public xl As New Excel.Application
        Public xlsheet As Excel.Worksheet
        Public xlwbook As Excel.Workbook
        Public j As Integer
        
        Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            MsgBox("Hello")
        
            xlwbook = xl.Workbooks.Open("D:\\sample.xls")
            xlsheet = xlwbook.Sheets.Item(1)
        
            TextBox1.Text = xlsheet.Cells(2, 1) ' row 2 col 1
            TextBox2.Text = xlsheet.Cells(2, 2) ' row 2 col 2 
        
        
            xl.ActiveWorkbook.Close(False, "D:\\sample.xls")
            xl.Quit()
        End Sub
        

        End Class

        I am getting the errors as: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Vbc.exe /noconfig /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Data,System.Drawing,System.Diagnostics,System.Windows.Forms /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 /rootnamespace:VBCheck /doc:obj\Debug\VBCheck.xml /define:"CONFIG=\"Debug\",DEBUG=-1,TRACE=-1,_MyType=\"WindowsForms\",PLATFORM=\"AnyCPU\"" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /main:VBCheck.My.MyApplication /debug+ /debug:full /out:obj\Debug\VBCheck.exe /resource:obj\Debug\VBCheck.Form1.resources /resource:obj\Debug\VBCheck.Resources.resources /target:winexe Form1.vb Form1.Designer.vb "My Project\AssemblyInfo.vb" "My Project\Application.Designer.vb" "My Project\Resources.Designer.vb" "My Project\Settings.Designer.vb" error BC30002: Type 'Excel.Application' is not defined. error BC30002: Type 'Excel.Worksheet' is not defined. error BC30002: Type 'Excel.Workbook' is not defined. How to get rid of this error?

        R Offline
        R Offline
        RobCroll
        wrote on last edited by
        #3

        Do you have Excel installed? Can you post import directives? This may help.

        "You get that on the big jobs."

        1 Reply Last reply
        0
        • R rupeshkp728

          I want to read excel sheet cells. I have written the following code in Visual Basic 2005 in single desktop environment with no net connectivity:

          Public Class Form1

          Public xl As New Excel.Application
          Public xlsheet As Excel.Worksheet
          Public xlwbook As Excel.Workbook
          Public j As Integer
          
          Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              MsgBox("Hello")
          
              xlwbook = xl.Workbooks.Open("D:\\sample.xls")
              xlsheet = xlwbook.Sheets.Item(1)
          
              TextBox1.Text = xlsheet.Cells(2, 1) ' row 2 col 1
              TextBox2.Text = xlsheet.Cells(2, 2) ' row 2 col 2 
          
          
              xl.ActiveWorkbook.Close(False, "D:\\sample.xls")
              xl.Quit()
          End Sub
          

          End Class

          I am getting the errors as: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Vbc.exe /noconfig /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Data,System.Drawing,System.Diagnostics,System.Windows.Forms /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 /rootnamespace:VBCheck /doc:obj\Debug\VBCheck.xml /define:"CONFIG=\"Debug\",DEBUG=-1,TRACE=-1,_MyType=\"WindowsForms\",PLATFORM=\"AnyCPU\"" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /main:VBCheck.My.MyApplication /debug+ /debug:full /out:obj\Debug\VBCheck.exe /resource:obj\Debug\VBCheck.Form1.resources /resource:obj\Debug\VBCheck.Resources.resources /target:winexe Form1.vb Form1.Designer.vb "My Project\AssemblyInfo.vb" "My Project\Application.Designer.vb" "My Project\Resources.Designer.vb" "My Project\Settings.Designer.vb" error BC30002: Type 'Excel.Application' is not defined. error BC30002: Type 'Excel.Worksheet' is not defined. error BC30002: Type 'Excel.Workbook' is not defined. How to get rid of this error?

          A Offline
          A Offline
          alainmarccavenaile
          wrote on last edited by
          #4

          You'll have to add Imports System.Runtime.InteropServices Imports Microsoft.Office.Interop.Excel

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups