Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

using Excell2007 files in vb.net 2005

Last post 03-23-2008 6:14 AM by sre08. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 10-26-2007 8:47 AM

    • kutadgu
    • Not Ranked
    • Joined on 10-26-2007
    • Turkey
    • New Member
    • Points 85

    using Excell2007 files in vb.net 2005

    Hi, i can use Excell 2000 Files in vb.net and i'm using Microsoft Excel 9.0.dll for this. But now, i have ofis2007 on my notebook and i want to develop vb.net 2005 projects which can use excell2007 files. Please help me. I dont know how i can use excell2007 files in vb.net 2005. There is an information on microsoft web page about this subject like this, " if you want to use excell2007 files in vb.net you must add reference Microsoft Excell 12.0 Object Library.". I added this library but an error  occured and vb.net cant use my code as blove

    Dim excelobject As New Excel.Application

    excelobject.Workbooks.Open(Application.StartupPath & "\rson.xls")

    Dim worksheet As New Excel.Worksheet

    worksheet = excelobject.ActiveWorkbook.ActiveSheet

    With worksheet

    .Cells(1, 1) = "open orders"

    .Cells(2, 1) = "---------------------------------"

    End With

     

    please help me using excell2007 in vb.net 2005 version. Thanks...

    • Post Points: 15
  • 10-26-2007 5:40 PM In reply to

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

    Re: using Excell2007 files in vb.net 2005

    Please switch Option Strict on. Please tell us in which line the error occurs and what the error message is. Knowing these facts I most propably will be able to fix your problem.

    • Post Points: 10
  • 10-26-2007 10:41 PM In reply to

    • kutadgu
    • Not Ranked
    • Joined on 10-26-2007
    • Turkey
    • New Member
    • Points 85

    Re: using Excell2007 files in vb.net 2005

    ok. Thanks for you, for your reply.

    After I add referans Microsoft Office 12.0 Object Library, i started to develop my project. My first line was as blove;

    Dim excelobject As New Excel.Application but there was an error like this:

    Type 'Excel.Application' is not defined.

    But if i add Microsoft Office 9.0 Object Library (using for office 2000), there was no error with this library. But under this condition, i cant use excell2007. I must use excell 2000 only.

    how can i declare an excel.application with Microsoft Office 12.0 object library .  

     

    • Post Points: 10
  • 10-27-2007 12:11 PM In reply to

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

    Re: using Excell2007 files in vb.net 2005

    You did not define Excel in your code, so VB does not know what Excel is. It is the same as when you have option strict and option explicit on and type something like 'myString = "hello world" '. In your project, please try to use this header:

    Option Strict On
    Option Explicit On
    Imports Excel = Microsoft.Office.Interop.Excel

    Before using a worksheet member you also need to do a type conversion (direct cast will also work):
    myWS = CType(myXL.ActiveSheet, Excel.Worksheet)

    The complete code could then look like this:
    Option Strict On
    Option Explicit On
    Imports Excel = Microsoft.Office.Interop.Excel
    
    Public Class Form1
        Private myXL As Excel.Application = New Excel.Application
        Private myWS As Excel.Worksheet = New Excel.Worksheet
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        myXL.Workbooks.Open(Application.StartupPath & "\rson.xls") 
        myXL.Visible = True
        myWS = CType(myXL.ActiveSheet, Excel.Worksheet)
        With myWS
            .Cells(1, 1) = "open orders"
            .Cells(2, 1) = "---------------------------------"
        End With
        myXL.Quit()
        myWS = Nothing
        myXL = Nothing
    End Sub
    
    End Class
    
    • Post Points: 10
  • 10-27-2007 10:36 PM In reply to

    • kutadgu
    • Not Ranked
    • Joined on 10-26-2007
    • Turkey
    • New Member
    • Points 85

    Re: using Excell2007 files in vb.net 2005

    Option Strict On

    Option Explicit On

    Imports Excel = Microsoft.Office.Interop.Excel

    Public Class Form1

    Private myXL As New Excel.Application

    Private myWS As New Excel.Worksheet

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    myXL.Workbooks.Open(Application.StartupPath & "\rson.xls")  there was an error="COM Exception was unhandled" "Old type or

    invalid library(HRESULT returns: 0x80028018 (TYPE_E_INVDATAREAD)

    myXL.Visible = True

    myWS = CType(myXL.ActiveSheet, Excel.Worksheet)

    With myWS

    .Cells(1, 1) = "open orders"

    .Cells(2, 1) = "---------------------------------"

    End With

    myXL.Quit()

    myWS = Nothing

    myXL = Nothing

    End Sub

    End Class

     

    Thanks for you again.  

    I used your codes and i added reference COM as Microsoft Excel 12.0 Object Library. But after start the project i have an error as shown on code line . I written the error in the error line.

    Please go on help me again.

     

      

    • Post Points: 10
  • 10-28-2007 4:37 PM In reply to

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

    Re: using Excell2007 files in vb.net 2005

    1. Please try to put the line that causes the error into a Try...Catch...End Try block and output the complete exception string. This way you may get additional info on the error.

    2. I used google to search for the specific error message and got some hints:

    - Some are saying that this indicates a conflict with your culture settings (date and time format, language settings, etc.).

    Please try EN-US first, then the most common settings for your country.

    - Some are saying that Excel is sometimes unable to determine the exact format of the file automatically. Maybe you try to change the file extension or use the OpenXML method instead of Open.

    - Some are saying that this error is caused when you fill an excel spreadsheet with the help of some outdated tools or programs. These tools are writting files that are working fine with older Office versions but fail to write proper Excel 2007 files.

    3. Your Excel file may be corrupt. Please create a simple excel sheet manually and test it with your program.

    • Post Points: 10
  • 10-29-2007 8:54 PM In reply to

    • kutadgu
    • Not Ranked
    • Joined on 10-26-2007
    • Turkey
    • New Member
    • Points 85

    Re: using Excell2007 files in vb.net 2005

    Thank you very much. I tested my regional settings.I have Turkish office 2007 but my regional settings were English UK. So there was a conflict. My projet was successful and my problem was solved when i changed my regional settings as my own country settings. 

    I meen i can use excel2007 files in my projets, thank you very much, your cincerily .

    • Post Points: 5
  • 03-23-2008 6:14 AM In reply to

    • sre08
    • Not Ranked
    • Joined on 03-23-2008
    • United Arab Emirates
    • New Member
    • Points 10

    Re: using Excell2007 files in vb.net 2005

    i found one here , plz look at this

     its abt vb.net 2005 with excel 2007

    http://vb.net-informations.com/excel-2007/vb.net_excel_2007_tutorials.htm

     

    sre,

     

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