Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

using a reference to work with "Excel.Application" and "Excel.Workbook"

Last post 05-10-2008 5:05 PM by bvasuraj. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 06-16-2006 3:58 PM

    • zasskar
    • Not Ranked
    • Joined on 06-16-2006
    • United States
    • New Member
    • Points 15

    using a reference to work with "Excel.Application" and "Excel.Workbook"

    Hello,

    I am trying to import/export Excel data with VB.NET based on examples I have found.  Unfortunately, Excel.Application, Excel.Workbook, and Excel.Worksheet get underlined (they are not defined).  Could you please tell me what I need to do differently?

            Dim objExcel As New Excel.Application()   ' Instance of Excel
            Dim objWorkbook As Excel.Workbook     'workbook object
            Dim objWorksheet As Excel.Worksheet     'worksheet object

    I did add a reference via Project > Add Reference > selecting the "COM" tab > and then selecting "Microsoft Excel 11.0 Object Library" and clicking "ok"

    I have the reference in my solution explorer window.

    I haven't worked with references before, so I'm not sure what to do next.  I thought that simply by adding the reference I would be good to go but that doesn't appear to be the case.  I added the Excel 11.0 Library because I'm using Excel 2003.

    Thank you in advance,
    michael

    • Post Points: 15
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 06-21-2006 3:17 PM In reply to

    • Zorro_ot
    • Top 500 Contributor
    • Joined on 01-25-2006
    • Addicted Member
    • Points 780

    Re: using a reference to work with "Excel.Application" and "Excel.Workbook"

    I'm just a hobby programmer, so I dont know if this solution is a good one. But you can try this code instead:

    Dim objExcel As New Microsoft.Office.Interop.Excel.Application    ' Instance of Excel 
    Dim objWorkbook As Microsoft.Office.Interop.Excel.Workbook      'workbook object 
    Dim objWorksheet As Microsoft.Office.Interop.Excel.Worksheet     'worksheet object

    Regards,
    Zorro

     

    I must correct myself. The code must be as follow:

    Dim objExcel As Microsoft.Office.Interop.Excel.Application
    Dim objWorkbook As Microsoft.Office.Interop.Excel.Workbook  
    Dim objWorksheet As Microsoft.Office.Interop.Excel.Worksheet   

    objExcel = New Microsoft.Office.Interop.Excel.Application    ' Instance of Excel 
    objWorkbook = New Microsoft.Office.Interop.Excel.Workbook      'workbook object 
    objWorksheet = New Microsoft.Office.Interop.Excel.Worksheet     'worksheet object

    • Post Points: 5
  • 06-26-2006 7:26 PM In reply to

    • demmith
    • Not Ranked
    • Joined on 06-26-2006
    • United States
    • New Member
    • Points 10

    Re: using a reference to work with "Excel.Application" and "Excel.Workbook"

    After creating the reference the next step is to use either the fully qualified name as shown in your first response or you may use this statement...

    Imports Microsoft.Office.Interop.Excel

    then you may declare objects like this...
    Dim wkb As Workbooks
    wkb.Open(filename) Dave





    • Post Points: 10
  • 05-10-2008 5:05 PM In reply to

    • bvasuraj
    • Not Ranked
    • Joined on 05-10-2008
    • India
    • New Member
    • Points 5

    Re: using a reference to work with "Excel.Application" and "Excel.Workbook"

    U have to include the references of microsoft excel which can be done as follows:

     Project -> Add References -> com -> microsoft excel 10.0 object library

     

    :)
     

     Thanks & Regards

    vasu dev 

    • Post Points: 5
Page 1 of 1 (4 items)