How to append Data to an existing Excel file?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • premMS143
    New Member
    • Nov 2008
    • 75

    How to append Data to an existing Excel file?

    How to append Data to an existing Excel file?
    means,
    I'm using VB as front end & once I exported the data to Excel file & saved it as 'ABC.xls'.

    Now, the question/doubt is;
    I addded some more records in VB.
    Now if I want to export these newly updated records to an already existing file 'ABC.xls' what shall I do..?
    Could anybody help me...? Pls....


    Thanks in advance.
    Waiting for your answer.
  • mrmelvin
    New Member
    • Aug 2008
    • 4

    #2
    This solution will help you find the first empty row number in a spreadsheet. After you know that number you would used the standard expression like worksheet.range ("A1").value .

    Dim excelApp As Excel.Applicati on = New Excel.Applicati on()
    Dim excelBook As Excel.Workbook
    Dim strPath As String = "C:\Documen ts and Settings\All Users\Documents \Intranet\Sysco ARL\uniqueinv-20081201-024-ALL.xls"
    excelBook = excelApp.Workbo oks.Open(strPat h, 0, False, 5, _
    System.Reflecti on.Missing.Valu e, System.Reflecti on.Missing.Valu e, _
    False, System.Reflecti on.Missing.Valu e, System.Reflecti on.Missing.Valu e, _
    True, False, System.Reflecti on.Missing.Valu e, False)
    Dim excelSheets As Excel.Sheets = excelBook.Sheet s
    Dim excelSheet As Excel.Worksheet = excelSheets(1)
    Dim excelRange As Excel.Range = excelSheet.Used Range
    excelRange.Spec ialCells(Excel. XlCellType.xlCe llTypeLastCell) .Activate()
    Dim intNewRow As Int32 = excelApp.Active Cell.Row + 1
    Dim strNewCellAddre ss As String = "A" & intNewRow
    excelSheet.Rang e(strNewCellAdd ress).Value = "this data goes in the first empty row"
    excelBook.Save( )
    excelBook.Close ()
    excelApp.Quit()
    Last edited by mrmelvin; Jan 16 '09, 08:35 PM. Reason: post was showing unwanted markup tags

    Comment

    • premMS143
      New Member
      • Nov 2008
      • 75

      #3
      ThanQ for your reply SIr.
      I will try it.

      Thanks & regards,
      Prem

      Comment

      • Kolags
        New Member
        • Oct 2007
        • 9

        #4
        Thank you mrmelvin.
        Your Solution is prefectly suitable to my problem.

        Comment

        Working...