Link to home
Start Free TrialLog in
Avatar of EBSI
EBSI

asked on

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

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

Avatar of EBSI
EBSI

ASKER

All,

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

Thank you,

EBSI
ScreenShot.jpg
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EBSI

ASKER

Although not specific, it did help.