How To Append Data To an Existing Excel File VB Express

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
This is the code i have right now
i Want to Copy data from an old excel book and add it to a new excel book
but i want to access this file as many times as i want to add more data but without replacing the old date
could someone please help me how to approach this
Protected Sub CustomFile_Click(sender As Object, e As EventArgs) Handles CustomFile.Click

Dim orgExcel As New Excel.Application
Dim orgBook As Excel.Workbook
Dim orgSheet As Excel.Worksheet
Dim newExcel As New Excel.Application
Dim newBook As Excel.Workbook
Dim newSheet As Excel.Worksheet



orgBook = orgExcel.Workbooks.Open("C:UsersjcoloniaDesktop" + OrgF.Text + ".xlsx")
orgSheet = orgBook.Sheets.Item(1)
orgSheet.Range(OrgRange1.Text + ":" + OrgRange2.Text).copy()
orgExcel.Visible = True Remove to hide the excel file

newExcel.DisplayAlerts = False Disable The SaveAs Alert
newBook = newExcel.Workbooks.Add
newSheet = newBook.Sheets.Item(1)
newSheet.Range(NewRange1.Text + ":" + NewRange2.Text).PasteSpecial()
newBook.SaveAs("C:UsersjcoloniaDesktopCopied.xlsx")
orgExcel.Quit()
newExcel.Quit()
OrgRange1.Text = ""
OrgRange2.Text = ""
NewRange1.Text = ""
NewRange2.Text = ""
OrgF.Text = ""
NewFile.Text = ""

View the full article
 
Back
Top