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

0 Responses to “VB Program to Append Excel”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: