VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 309,254 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,507 people online right now. Registration is fast and FREE... Join Now!




Exporting Values to Excel

 

Exporting Values to Excel

miketeebo

4 Oct, 2009 - 08:36 AM
Post #1

New D.I.C Head
*

Joined: 12 Aug, 2009
Posts: 21

I am working on a form for my program that will export its values to an excel spreadsheet.

I just started looking for information to help me. This is what I currently have:

CODE

Public Class frmResults
    'To open Excel
    Dim ApExcel As Object
    Dim ApSheet As Object
    Dim ApBook As Object

   Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

        'Creates an object
        ApExcel = CreateObject("Excel.application")
      
        ' So you can see Excel
        ApExcel.Visible = True

        'Adds a new book.
        ApExcel.Workbooks.Add(C:\Users\Mike\Desktop\PTText.xlsx")

        Dim i As Integer
        For i = 1 To 700 + 1
            If ApSheet.Range("Ai").value = "" Then
                ApSheet.Range("Bi").value = FName
                ApSheet.Range("Ci").value = LName
                ApSheet.Range("Di").value = date2
                ApSheet.Range("Ei").value = Age
                ApSheet.Range("Fi").value = Pushup
                ApSheet.Range("Gi").value = Situp
                ApSheet.Range("Hi").value = BComp
                ApSheet.Range("Ii").value = Run
                ApSheet.Range("Ji").value = Score
                ApSheet.Range("Ki").value = Fail
            End If
        Next i
    End Sub
End Class


What I want this to do is to search through a spreadsheet and then add a new line of information when it doesn't fina anything in the "A" column.

Currently I am getting a "COMException was Unhandled" problem on this line of code:

CODE

        ApExcel.Workbooks.Add(C:\Users\Mike\Desktop\PTText.xlsx")


I am hoping that I can get some help figuring out what I can do.

Thanks for your help.

User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 1)

June7

RE: Exporting Values To Excel

4 Oct, 2009 - 11:47 AM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 486



Thanked: 38 times
My Contributions
Your code tries to Add a new workbook but don't you want to open an existing workbook?
I am not as familiar with VB.net syntax so here is a link to sample code:
http://vb.net-informations.com/excel-2007/...7_open_file.htm
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/26/09 09:55AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month