Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2008 > Visual Basic 2008 Essentials
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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.
Reply With Quote
  #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...
Reply With Quote
  #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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:12 PM.


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