473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

I cant create a new file only works with a created file and can't write in the excell

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
Nov 19 '13 #1
0 826

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: KULJEET | last post by:
control file not created at time of installtion of oracle database now how we can create it see alert file Dump file e:\ORacle\admin\new\bdump\newALRT.LOG Tue Sep 09 10:45:53 2003 ORACLE...
2
by: sonu | last post by:
I am tring to create activexobject like var Fo =new ActiveXObject("Scripting.FileSystemObject"); but i am finding error that automation server cant create object any help
7
by: Dave Elliott | last post by:
I have a db that is split and shared on the network. I gave the user a custom menu to use. We both use the same tables of course. On my PC I can create new records using their menu on my PC, on...
11
by: Dica | last post by:
i'm getting an error about 'the process cannot access the file becaise it is being used by another process.' write after i've created a new file and try to open it for writing with xmlTextWriter....
5
by: cwbp15 | last post by:
Using Visual Studio C# When I ran the following code: System.IO; private void Button1_Click(object sender, System.EventArgs e) { //FileStream fs = File.Create(Server.MapPath("test.txt"));...
3
by: Steve Richter | last post by:
running a simple vbscript in an .htm page that starts excel and loads the spreadsheet with the contents of a <table> ... </table> getting an "Error: ActiveX component cant create object....
10
by: Minh | last post by:
I search in all the Disscussion but can not found. How can I create a MS Access Database file using C# code with a given Table Structure ? For example, I want to create a Access Database File...
7
by: ytoledano | last post by:
Hi, I'm using PerlScript in my ASP page and I have the following problem: Each time the page is refreshed a CSV file is created. I want this file to be available for download. The problem is I...
3
by: Matthew Warren | last post by:
I have the following piece of code, taken from a bigger module, that even as I was writing I _knew_ there were better ways of doing it, using a parser or somesuch at least, but learning how wasn't...
3
by: Begreen | last post by:
Hi All, I wrote a java program which outputs a xml file! But I would prefer this program to insert the DTD code on the fly, in the xml file when created! I want the xml file to look like...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.