Link to home
Start Free TrialLog in
Avatar of tdsully
tdsully

asked on

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
Avatar of tdsully
tdsully

ASKER

Is there a way to do this without instantiating excel at all?
Hi tfsully, what is your question exactly, because what you are doing seems to be the correct way
Avatar of tdsully

ASKER

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.

ASKER CERTIFIED SOLUTION
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial