Data Entry Into Excel

     

     

    Imports Excel = Microsoft.Office.Interop.Excel
    Public Class Form1
    Public XLApp As Excel.Application, WKB As Excel.Workbook, SH As Excel.Worksheet, WKBPath As String
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Me.Close()
    WKB.SaveAs(WKBPath)
    XLApp.DisplayAlerts = True
    XLApp.Quit()
    SH = Nothing
    WKB = Nothing
    XLApp = Nothing
    MsgBox("Saved and Disconnected")
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim Lastrow As Integer
    Lastrow = SH.Range("A" & SH.Rows.Count).End(Excel.XlDirection.xlUp).Row + 1
    SH.Range("A" & Lastrow).Value = Me.TextBox1.Text
    Me.TextBox1.Clear()
    SH.Range("B" & Lastrow).Value = Me.TextBox2.Text
    Me.TextBox2.Clear()
    SH.Range("C" & Lastrow).Value = Me.TextBox3.Text
    Me.TextBox3.Clear()
    SH.Range("D" & Lastrow).Value = Me.TextBox4.Text
    Me.TextBox4.Clear()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    XLApp = New Excel.Application
    XLApp.Visible = True
    WKBPath = "C:\Users\Pavan\Desktop\sample.xlsx"
    WKB = XLApp.Workbooks.Add(WKBPath)
    SH = WKB.Sheets("Sheet1")
    XLApp.DisplayAlerts = False
    'MsgBox("Connected")
    End Sub
    End Class