Solved

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

Posted on 2011-09-23
3
635 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

680 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