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.Applic ation")
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(File name:=MMpa th, UpdateLinks:=False, ReadOnly:=False)
wbk2 = oExcel.Workbooks.Open(File name:=Me.P ath, UpdateLinks:=False, ReadOnly:=False)
This is where the problem is so far: ************************** **
wbk.sheets.add(wbk2.active sheet)
wbk.save()
wbk.close()
wbk2.save()
wbk2.close()
************************** ********** ********** *********
End While
Connection.Close()
Me.Rpt = MMrpt
Me.Path = MMpath
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.Applic
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(File
wbk2 = oExcel.Workbooks.Open(File
This is where the problem is so far: **************************
wbk.sheets.add(wbk2.active
wbk.save()
wbk.close()
wbk2.save()
wbk2.close()
**************************
End While
Connection.Close()
Me.Rpt = MMrpt
Me.Path = MMpath
Hi tfsully, what is your question exactly, because what you are doing seems to be the correct way
ASKER
Hi,
Thanks for your feed back
wbk.sheets.add(wbk2.active sheet)
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.
Thanks for your feed back
wbk.sheets.add(wbk2.active
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER