» »

[Visual studio .NET] Rabim pomoč

[Visual studio .NET] Rabim pomoč

ml007 ::

Imam en problem in to da bi v Excelu Zapisal podatke vsakič ko jih shranim mi jih shrani v isto vrsto
Rad bi pa da jih shrani v naslednjo vrsto kjer so bili prejšnič shranjeni podatki.
Se vam že v naprej zahvaljujem
Lp Matevž [Visual studio .NET] Rabim pomoč

darkolord ::

Pokaži kodo, ki jo zdaj uporabljaš

ml007 ::

Dim Excel As Object
Dim Book As Object
Dim Sheet As Object

'Start a nev workbook in Excel
Excel = CreateObject("Excel.Application")
Book = Excel.Workbooks.Add

'Add data to cells of the first worksheet in the new workbook
Sheet = Book.Worksheets(1)
Sheet.Range("C1").Value = "Datum"
Sheet.Range("D1").Value = "Destinacija"

Sheet.Range("B1:D1:E1:F1:G1:I1:J1:K1:L1:N1:O1:P1:Q1").Font.Bold = True

Sheet.Range("C2").Value = DateTimePicker1.Text
Sheet.Range("D2").Value = Destinacija.Text
' Save the sheet to c:Book1
Book.SaveAs("C:\Book1.xls")
Excel.Quit()
'Exit application
Application.Exit()
End Sub
End Class
To je ta koda katero uporabljam
Lp Matevž

darkolord ::

ja to je pa zato ker imaš v kodi točno določeno celico kamor naj te podatke zapiše
Sheet.Range("C2").Value = DateTimePicker1.Text
Sheet.Range("D2").Value = Destinacija.Text

to lahko rešiš recimo tako, da najprej poiščeš prazno celico v stolpcu... približno nekaj v tem stilu:

Dim i As Integer
For i = 1 To Sheet.Rows.Count
If Len(Sheet.Range("C" & i).Value) = 0 Then
Exit For
End If
Next i

Sheet.Range("C" & i).Value = "Datum"
Sheet.Range("D" & i).Value = "Destinacija"

'tale replace ti pač te "1" nadomesti s številko vrstice
Sheet.Range(Replace("B1:D1:E1:F1:G1:I1:J1:K1:L1:N1:O1:P1:Q1","1",i)).Font.Bold = True

Sheet.Range("C" & i).Value = DateTimePicker1.Text
Sheet.Range("D" & i).Value = Destinacija.Text

Zgodovina sprememb…

ml007 ::

Mi ne dela tud tko k je prej blo
noče niti v excelu narest tabele

darkolord ::

Ja sej morš sam tisti vmesni del zamenjat :D... tale:

Sheet.Range("C1").Value = "Datum"
Sheet.Range("D1").Value = "Destinacija"

Sheet.Range("B1:D1:E1:F1:G1:I1:J1:K1:L1:N1:O1:P1:Q1").Font.Bold = True

Sheet.Range("C2").Value = DateTimePicker1.Text
Sheet.Range("D2").Value = Destinacija.Text

ml007 ::

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Excel As Object
Dim Book As Object
Dim Sheet As Object

'Start a nev workbook in Excel
Excel = CreateObject("Excel.Application")
Book = Excel.Workbooks.Add

'Add data to cells of the first worksheet in the new workbook
Sheet = Book.Worksheets(1)
Dim i As Integer
For i = 1 To Sheet.Rows.Count
If Len(Sheet.Range("C" & i).Value) = 0 Then
Exit For
End If
Next i

Sheet.Range("C" & i).Value = "Datum"
Sheet.Range("D" & i).Value = "Destinacija"

'tale replace ti pač te "1" nadomesti s številko vrstice
Sheet.Range(Replace("B1:D1:E1:F1:G1:I1:J1:K1:L1:N1:O1:P1:Q1", "1", i)).Font.Bold = True

Sheet.Range("C" & i).Value = TextBox1.Text
Sheet.Range("D" & i).Value = TextBox2.Text


' Save the sheet to c:Book1
Book.SaveAs("C:\Book1.xls")
Excel.Quit()
'Exit application
Application.Exit()

End Sub
End Class
Tko sem naredil kot si rekel pa mi ne dela tako da bi vskič v novo vrstico napisal
Pa še sedaj mi noče napisati Datum in Destinacija
Tko da bi prosil če kdo ve kao bi se dalo naresti da bi vsakič
Ko bi vpisoval podatke da bi ji shranilo v nslednjo vrstico ki je prazna n+in ne v vrstico ki jr definerana
Tko da bi naslednjič ko bi shranil da bi jo zapisalv v C3 in D3 in ne v C2 inD2
Lepo bi prosil da mi pomagate se vam v naprej zahvaljujem
Lp Matevž

darkolord ::

Aja sori en kos kode sm pozabu... tkole pa dela:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Excel As Object
Dim Book As Object
Dim Sheet As Object

'Start a nev workbook in Excel
Excel = CreateObject("Excel.Application")
'
If Dir("C:\Book1.xls") = "" Then
Book = Excel.Workbooks.Add
Else
Book = Excel.Workbooks.Open("C:\Book1.xls")
End If

'Add data to cells of the first worksheet in the new workbook
Sheet = Book.Worksheets(1)
Dim i As Integer
For i = 1 To Sheet.Rows.Count
If Len(Sheet.Range("C" & i).Value) = 0 Then
Exit For
End If
Next i

Sheet.Range("C" & i).Value = "Datum"
Sheet.Range("D" & i).Value = "Destinacija"

'tale replace ti pač te "1" nadomesti s številko vrstice
Sheet.Range(Replace("B1:D1:E1:F1:G1:I1:J1:K1:L1:N1:O1:P1:Q1", "1", i)).Font.Bold = True

Sheet.Range("C" & i).Value = TextBox1.Text
Sheet.Range("D" & i).Value = TextBox2.Text


' Save the sheet to c:Book1
If Dir("C:\Book1.xls") = "" Then
Book.SaveAs("C:\Book1.xls")
Else
Book.Save
End If
Excel.Quit()
'Exit application
Application.Exit()
End Sub

ml007 ::

darkolord Najlepša hvala
Deluje
Lp Matevž

darkolord ::

np...


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

Excel: tiskanje po vrsticah

Oddelek: Pomoč in nasveti
7779 (692) luksorzi
»

[Excel]Kako izvleči vrednost?

Oddelek: Programiranje
223359 (3082) Mobidick
»

[Excel]Vrednost celice = ime dokumenta

Oddelek: Programska oprema
314256 (3678) veteran
»

Prosim za pomoč pri VBA

Oddelek: Programiranje
351739 (1542) apachee
»

Visual Basic in Excel

Oddelek: Programiranje
262296 (1862) Vesoljc

Več podobnih tem