Solved

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

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

Suggested Solutions

Title # Comments Views Activity
Macro Excel - Multiple If conditions 2 81
Interview question Javascript, database 12 82
Problem to picture file 20 65
Not seen Link button 5 54
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

808 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