Solved

Using VB.net  2010 to read/write to existing or new Excel 2007 worksheet

Posted on 2011-09-23
3
638 Views
Last Modified: 2013-11-26
All,
I'm about ready to go back to VB6.

I need to develop a program that simply reads and writes to an excel 2007 file. I can do it in VB6 and to Excel 2003, but not 2007. I'm using tne Microsoft Excel 12.0 library.

I'm getting "Interop type '_ExcelApplication Class' cannot be embedded. Use the applicable interface instead." (Line 10)

Although far from being an "expert", I can handle VB6 fairly well. VB.net is kicking my "#@#".
Thanks for the help,

EBSI (W. Bailey)


_
Imports Microsoft.Office.Interop

Public Class Form1
    'http://www.visual-basic-tutorials.com/WriteToExcel2007.php
    Dim APP As Excel.Application
    Dim worksheet As Excel.Worksheet
    Dim workbook As Excel.Workbook

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        APP = New Excel._ExcelApplicationClass
        workbook = APP.Workbooks.Open("C:\MBS_Jobs_Weld\jvtest\Test.xls")
        worksheet = workbook.Worksheets("sheet1")

    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Myfile As String
        Myfile = Dir("C:\MBS_Jobs_Weld\jvtest\Test.xls")
        Stop
        TextBox1.Text = worksheet.Cells(1, 1).Value
        TextBox2.Text = worksheet.Cells(1, 2).Value
    End Sub

    Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        workbook.Save()
        workbook.Close()
        APP.Quit()
    End Sub



End Class

Open in new window

0
Comment
Question by:EBSI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:EBSI
ID: 36587120
All,

I got the program to compile, but now get this error.

Thank you,

EBSI
ScreenShot.jpg
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 36599386
1) I would use the ACE driver, if you aren't, in the connection string.

2) You can use OLE DB to read the Excel

3) You can also use Open XML library to read Excel.

If you are saying that you want to go back to VB6, then I would say that you are in desparate need of some small successes, to bolster your confidence in something completely new, because we would hate to see you go over the one thing that .NET has a problem with (COM interop).
0
 

Author Closing Comment

by:EBSI
ID: 36681516
Although not specific, it did help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question