Pass Values from VB.Net application to Excel Template and back to the application?

I am in need of assistance in passing values from a VB.Net application to an Excel spreadsheet template and than be able to pass it back to the program for editing.  

Here's an overview of the process and what I want to accomplish.  I want to create a vb.net program that has the similar form or template as the Excel spreadsheet template, when a person creates a new form and save it will insert the values from the program to the Excel template.  If they open an existing form (Using conditions to determine if it's a new or existing form), the program will pull the value from the Excel spreadsheet and populate the application for editing.  I think that if they hit "New" to create a new form, it will default to the template otherwise it will use the existing Excel spreadsheet for this.

Summary:

1)  How would I pass value from VB.Net application to an existing Excel Template?  Please provide example of opening the Template and than passing from VB.Net application to the template.  For example txtFName will be pass to cell A1, txtLName to cell B1, etc....

2)  If the user opens an existing excel spreadsheet, how would I read the excel spreadsheet and pass it to the application for editing?  For example the spreadsheet A1 has value "Jon", how would I pass that to textbox txtFName?
holemaniaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KudzullcCommented:
Hi holemania,

For reference try this Question
I got the method exporting a DataSet / DataTable to Excel file from:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20744146.html

========================================================
Imports Excel
Imports System.Runtime.InteropServices

Public Class ExportExcel
    Sub Export_To_Excel(ByVal dtSource As System.Data.DataTable, ByVal sFileName As String)

        Dim iRowCount As Integer = dtSource.Rows.Count
        Dim iColCount As Integer = dtSource.Columns.Count
        Dim oData(iRowCount, iColCount) As Object

        Dim iRow As Integer, iCol As Integer
        For iRow = 0 To iRowCount - 1
            For iCol = 0 To iColCount - 1
                oData(iRow, iCol) = dtSource.Rows(iRow).Item(iCol)
            Next
        Next

        ' Start Excel and get Application object
        Dim oExcel As Excel.Application = New Excel.Application()
        'oExcel.Visible = True  ' Make visible

        ' Get a new workbook
        Dim oBook As Excel._Workbook = CType(oExcel.Workbooks.Add(Missing.Value), Excel._Workbook)
        Dim oSheet As Excel._Worksheet = CType(oBook.ActiveSheet, Excel._Worksheet)

        Dim oRange As Excel.Range = oSheet.Range("A1")
        oRange = oRange.Resize(iRowCount, iColCount)
        oRange.Value = oData

        oSheet.SaveAs(sFileName)
        oExcel.Workbooks.Close()
        oExcel.Quit()

        oBook = Nothing
        oSheet = Nothing
        oExcel = Nothing
    End Sub
End Class


Part 2 of your question is to pay attention to this part
  Dim iRow As Integer, iCol As Integer
        For iRow = 0 To iRowCount - 1
            For iCol = 0 To iColCount - 1
                oData(iRow, iCol) = dtSource.Rows(iRow).Item(iCol)
            Next
        Next

can be modified dramatically to get this...
                   txtFName.text  = dtSource.Rows(A).Item(1)

Hope this helps.  I have NOT tried this code so good luck. It should put you off in right direction.

Best Regards,
Lucas
   
       

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
holemaniaAuthor Commented:
Sorry for getting back so late.  I was on Vacation and just got back.

It is working, but can you give me an example of opening a template?  For example we have an existing Excel spreadsheet that I want to pass the value to each cell.
KudzullcCommented:
holemania,
Do you mean opening a template fromVB?  I dont know if you can do that but I may be wrong.  Which really only means i have never done it before.  

gl,
Lucas
holemaniaAuthor Commented:
I figured it out.  I meant opening a Excel template.  See I want to use an existing template and fill that template with values from the VB application.  I switched to VB and not VB.Net because we were having some issues with trusting the assembles so it seems to work out with your example.  Just need to tweak it a little.

Thanks.
KudzullcCommented:
Great!

Thanks for the points.

gl,
Lucas
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.