EDN Admin
Well-known member
I have a question,
With this code i write some text to a excel sheet en print it out.
Works fine
But i want to save the file , and ad some more data to the sheet in the next empty row
Now it is going to row 1 cel a en b
Next time is has to go to row 2 a en b and so on
The next empty row.
Imports Microsoft.Office.Core<br/>
<br/>
Imports Microsoft.Office.Interop<br/>
<br/>
Public Class Form1<br/>
Private Worksheets As Object<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br/>
InitializeComponent()<br/>
Dim AppExcel As Object<br/>
Dim workBook As Object<br/>
AppExcel = CreateObject("Excel.Application")<br/>
<br/>
<br/>
workBook = AppExcel.Workbooks.Open(My.Application.Info.DirectoryPath & "test.xls")<br/>
AppExcel.Visible = False<br/>
Worksheets = workBook.worksheets<br/>
<br/>
AppExcel.Visible = True<br/>
<br/>
<br/>
Worksheets("blad1").Cells(1, 1).value = Form2.TextBox1.Text<br/>
Worksheets("blad1").Cells(1, 2).value = Form2.TextBox2.Text<br/>
<br/>
<br/>
<br/>
Worksheets("blad1").PrintOut()<br/>
<br/>
<br/>
<br/>
<br/>
Dim oXL As Application<br/>
Dim oWB As Excel.Workbook<br/>
Dim oSheet As Excel.Workbook<br/>
Dim oRng As Excel.Range<br/>
<br/>
<br/>
workBook.Saved = False<br/>
<br/>
<br/>
Make sure that you release object references.<br/>
oRng = Nothing<br/>
oSheet = Nothing<br/>
oWB = Nothing<br/>
AppExcel.Quit()<br/>
oXL = Nothing<br/>
<br/>
GC.Collect()<br/>
<br/>
Me.Close()<br/>
<br/>
End Sub<br/>
End Class
View the full article
With this code i write some text to a excel sheet en print it out.
Works fine
But i want to save the file , and ad some more data to the sheet in the next empty row
Now it is going to row 1 cel a en b
Next time is has to go to row 2 a en b and so on
The next empty row.
Imports Microsoft.Office.Core<br/>
<br/>
Imports Microsoft.Office.Interop<br/>
<br/>
Public Class Form1<br/>
Private Worksheets As Object<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br/>
InitializeComponent()<br/>
Dim AppExcel As Object<br/>
Dim workBook As Object<br/>
AppExcel = CreateObject("Excel.Application")<br/>
<br/>
<br/>
workBook = AppExcel.Workbooks.Open(My.Application.Info.DirectoryPath & "test.xls")<br/>
AppExcel.Visible = False<br/>
Worksheets = workBook.worksheets<br/>
<br/>
AppExcel.Visible = True<br/>
<br/>
<br/>
Worksheets("blad1").Cells(1, 1).value = Form2.TextBox1.Text<br/>
Worksheets("blad1").Cells(1, 2).value = Form2.TextBox2.Text<br/>
<br/>
<br/>
<br/>
Worksheets("blad1").PrintOut()<br/>
<br/>
<br/>
<br/>
<br/>
Dim oXL As Application<br/>
Dim oWB As Excel.Workbook<br/>
Dim oSheet As Excel.Workbook<br/>
Dim oRng As Excel.Range<br/>
<br/>
<br/>
workBook.Saved = False<br/>
<br/>
<br/>
Make sure that you release object references.<br/>
oRng = Nothing<br/>
oSheet = Nothing<br/>
oWB = Nothing<br/>
AppExcel.Quit()<br/>
oXL = Nothing<br/>
<br/>
GC.Collect()<br/>
<br/>
Me.Close()<br/>
<br/>
End Sub<br/>
End Class
View the full article