VB.net / Excell application Manipulation

I am trying to write code that will open two Excel workbooks and paste one file to the "Master" file as a new sheet in VB.net.
Along with this request, I would like some help in trying to find a good resource for the microsoft object model.  What I have found so far is 100 ways to do one thing.  I would like to find something that is streamlined.

The code I have so far is:

            Dim oExcel, wbk, wbk2 As Object
            oExcel = CreateObject("Excel.Application")

            Dim oMain, w2 As Excel.Workbook
            Dim oSheet As Excel.Sheets
            Dim MMrpt As String = Me.Rpt
            Dim MMpath As String = Me.Path

            'Try
            Connection.Open()
            Dim gCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(sql, Connection)
            Dim ReportInfo As SqlClient.SqlDataReader = gCommand.ExecuteReader
            While ReportInfo.Read
                Me.Rpt = ReportInfo(0).ToString
                Me.Initialize()
                Me.SetParameters()
                Me.ExportType()
                wbk = oExcel.Workbooks.Open(Filename:=MMpath, UpdateLinks:=False, ReadOnly:=False)
                wbk2 = oExcel.Workbooks.Open(Filename:=Me.Path, UpdateLinks:=False, ReadOnly:=False)

This is where the problem is so far:   ****************************

                wbk.sheets.add(wbk2.activesheet)  
                wbk.save()
                wbk.close()
                wbk2.save()
                wbk2.close()
*******************************************************

            End While
            Connection.Close()
            Me.Rpt = MMrpt
            Me.Path = MMpath
tdsullyAsked:
Who is Participating?
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.

tdsullyAuthor Commented:
Is there a way to do this without instantiating excel at all?
0
RonaldBiemansCommented:
Hi tfsully, what is your question exactly, because what you are doing seems to be the correct way
0
tdsullyAuthor Commented:
Hi,

Thanks for your feed back

wbk.sheets.add(wbk2.activesheet)  

I come up with an error on this line.  What I would like to do is append two excel files together without opening the excel
application.  I would give you the exact error message, but I cannot test the app right now because of our month end reporting.

0
RonaldBiemansCommented:
Hi TDsully, I tested this and this seems to work

Dim oExcel As New Excel.Application
Dim oMain, w2 As Excel.Workbook

        oMain = oExcel.Workbooks.Open(Filename:="c:\t1.xls", UpdateLinks:=False, ReadOnly:=False)
        w2 = oExcel.Workbooks.Open(Filename:="c:\t2.xls", UpdateLinks:=False, ReadOnly:=False)
        w2.Sheets(1).Copy(After:=oMain.Sheets(1))
        oMain.Save()
        oMain.Close()
        w2.Save()
        w2.Close()
        oExcel = Nothing
0

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
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.