Imports Microsoft.Office.Interop
Public Class Form2
Private Property newinfo As Object
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet
Dim lastRow As Long
Dim FILE_NAME As String = "C:\Users\Galamba\Documents\Multas\Livro"
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open(FILE_NAME)
xlWorksheet = xlWorkBook.Sheets.Item(1)
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
objWriter.Write(TextBox1.Text)
objWriter.Close()
MsgBox("Completo")
Else
MsgBox("Efectuado com sucesso")
End If
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open("C:\Users\Galamba\Documents\M ultas\Livro")
xlWorksheet = xlWorkBook.Worksheets(1)
xlApp.Visible = False
lastRow = xlWorksheet.Range("A" & xlApp.Rows.CountLarge).End(Excel.XlDirection.xlUp) .Row + 1
With xlWorksheet
.Range("A1").Value = "ID Interno"
.Range("A1").ColumnWidth = 20
.Range("B1").Value = "Data de inserção"
.Range("B1").ColumnWidth = 20
.Range("C1").Value = "NºAuto/Processo"
.Range("C1").ColumnWidth = 20
.Range("D1").Value = "NºOficio"
.Range("D1").ColumnWidth = 20
.Range("E1").Value = "Matricula"
.Range("E1").ColumnWidth = 20
.Range("F1").Value = "Hora"
.Range("F1").ColumnWidth = 20
.Range("G1").Value = "Data Multa"
.Range("G1").ColumnWidth = 20
.Range("H1").Value = "Montante"
.Range("H1").ColumnWidth = 20
.Range("I1").Value = "Data Notificação"
.Range("I1").ColumnWidth = 20
.Range("J1").Value = "Organismo"
.Range("J1").ColumnWidth = 20
.Range("K1").Value = "Portagens"
.Range("K1").ColumnWidth = 20
.Range("A" & lastRow).Value = Me.TextBox1.Text
.Range("B" & lastRow).Value = Me.TextBox2.Text
.Range("C" & lastRow).Value = Me.TextBox3.Text
.Range("D" & lastRow).Value = Me.TextBox4.Text
.Range("E" & lastRow).Value = Me.TextBox5.Text
.Range("F" & lastRow).Value = Me.TextBox6.Text
.Range("G" & lastRow).Value = Me.TextBox7.Text
.Range("H" & lastRow).Value = Me.TextBox8.Text
.Range("I" & lastRow).Value = Me.TextBox9.Text
.Range("J" & lastRow).Value = Me.RadioButton1.Text
.Range("J" & lastRow).Value = Me.ComboBox1.Text
.Range("J" & lastRow).Value = Me.ComboBox2.Text
.Range("J" & lastRow).Value = Me.ComboBox3.Text
.Range("k" & lastRow).Value = Me.CheckBox1.Text
.Range("k" & lastRow).Value = Me.CheckBox2.Text
.Range("k" & lastRow).Value = Me.CheckBox3.Text
.Range("k" & lastRow).Value = Me.CheckBox4.Text
End With
xlWorkBook.Save()
xlWorkBook.Close()
releaseObject(xlWorkBook)
releaseObject(xlWorksheet)
xlApp.Quit()
releaseObject(xlApp)
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub