Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2008 > Visual Basic 2008 Essentials
| Search | Today's Posts | Mark Forums Read
Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Essentials section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 9th, 2008, 03:05 AM
Registered User
 
Join Date: Aug 2005
Location: Surabaya, East Java, Indonesia.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Exsharaen
Default Error opening Excel 2007 files in Express Edition

Hi,

I want to open Excel 2007 file then retrieve some data inside. I used this code, let's say under Form1_Load:

Code:
Imports Microsoft.Office.Interop
...
Dim xlApp As New Excel.Application, xlWorkbook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet

Try
' The following line always fails
    xlWorkbook = xlApp.Workbooks.Open(My.Application.Info.DirectoryPath & _
"\Work Report.xlsx") 
    xlWorksheet = xlWorkbook.Sheets("April 2008")
    Label1.Text = xlWorksheet.Cells("B2")
Catch ex As Exception
    MessageBox.Show(ex.ToString)
End Try
...
I have added a reference to Microsoft Excel 12.0 Object Library.

When I test this code, I always get an error:

System.Runtime.InteropServices.COMException (0x80028018):
Old format or invalid type library.
(Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))
   at Microsoft.Office.Interop.Excel.Workbooks.Open(Stri ng Filename,
Object UpdateLinks, Object ReadOnly, Object Format, Object Password,
Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin,
Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru,
Object Local, Object CorruptLoad)
   at Sample.Form3.Form3_Load(Object sender, EventArgs e) in
D:\My Documents\Visual Studio 2008\Projects\Sample\Sample\Form3.vb:line 24

The VB 2008 samples about Excel application also don't work and throw the same exception.

I already did a workaround as written here: http://blogs.msdn.com/eric_carter/ar...15/429515.aspx
(since my locale is set to Indonesian), but it also didn't work.

Does anyone know how to overcome this in VB 2008 Express Edition?

Thank you.
  #2 (permalink)  
Old April 9th, 2008, 11:32 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Try creating a new workbook instead of trying to open an existing workbook,
to distinguish whether it is the file itself, or it the file-opening mechanism.

(Also, could you edit your original posting so that the error line is not so
long? Because it is in CODE tags, the browser will not wrap the line, and to
read you post, I need to horizontally scroll back and forth. Perhaps you
could put an asterisk as the comment, and explain it outside the CODE tags...
  #3 (permalink)  
Old April 25th, 2008, 01:47 AM
Registered User
 
Join Date: Aug 2005
Location: Surabaya, East Java, Indonesia.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Exsharaen
Default

Hi,

I'm sorry for the late reply. Creating a new workbook also fails. Fortunately, my friend gave me an alternative I had not found anywhere else. It seems my locale is the source of my problem, since I don't use English. So, I need to add this line:

Code:
System.Threading.Thread.CurrentThread.CurrentCulture = _ 
System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
before attempting to open or create a new workbook.

Thank you anyway for your guidance.



Similar Threads
Thread Thread Starter Forum Replies Last Post
Integrating Excel 2007 into VB 2005 express jffrs_20 Visual Studio 2005 0 October 12th, 2008 10:49 PM
SQL Server 2005 Express Edition: Error message jsbotts713 SQL Server 2005 1 September 26th, 2007 02:03 PM
Issue Opening Form in Access 2007 Laurel Access 0 July 20th, 2007 03:59 PM
Is C# 2005 Express Edition enough? eqv41dp C# 2005 0 January 4th, 2007 01:41 AM
Opening Excel and Excel files dinosaur_uk VB.NET 2002/2003 Basics 3 September 17th, 2004 03:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.