Archive for the 'Programming' Category

VB Program to Append Excel

The below program will be helpful for you to append a data in the last row of the excel sheet.

Add Microsoft Excel Object Library in project ->references
Dim xl As New Excel.Application
Dim xlsheet As Excel.Worksheet
Dim xlwkbook As Excel.Workbook
Private Sub Command1_Click()
Set xlwkbook = xl.Workbooks.Open(“c:\Test\test.xlsx”)
Set xlsheet = xlwkbook.Sheets.Item(1)
If xl.WorksheetFunction.CountA(xlsheet.Cells) = 0 Then lastrow = 1 Else
lastrow = xlsheet.UsedRange.Rows.Count + xlsheet.UsedRange.Row
‘read input from text boxes
xlsheet.Cells(lastrow, 1) = Text1.Text
xlsheet.Cells(lastrow, 2) = Text2.Text
xl.ActiveWorkbook.Close False, “c:\Test\test.xlsx”
Set xlwbook = Nothing
Set xl = Nothing
end sub