von witchcorp » Sa, 11.03.2006 23:22
Hallo Rainer,
das klappt nicht. Der Cursor landet immer noch in der Reihe nach dem letzten Eintrag.
Ich hab jetzt folgendes Makro:
Code: Alles auswählen
REM ***** BASIC *****
Private Sub OKButton_Click()
DIM dat As Date
DIM hab As Currency
DIM beschr As String
DIM oCell As Object
Dim oDoc As Object
Dim oSheet As Object
Dim oComboBox As Object
Dim oDateField As Object
Dim oCurrencyField As Object
Dim oCursor As Object
Dim nEndCol As Integer
Dim nEndRow As Integer
oDoc = ThisComponent
oSheet = oDoc.Sheets.GetByName("Formular")
oForm = oSheet.DrawPage.Forms.GetByName("Standard")
oDateField = oform.getByName("oDateFieldDatum")
dat = CDateFromIso(oDateField.date)
oSheet = oDoc.Sheets.GetByName("Formular")
oForm = oSheet.DrawPage.Forms.GetByName("Standard")
oCurrencyField = oform.getByName("oCurrencyFieldHaben")
hab = oCurrencyField.value
oSheet = oDoc.Sheets.GetByName("Formular")
oForm = oSheet.DrawPage.Forms.GetByName("Standard")
oComboBox = oform.getByName("oComboBoxBeschreibung")
beschr = oComboBox.text
oDocument=ThisComponent
oSheet = ThisComponent.Sheets.getByName( "Materialaufwand" )
nEndCol = getLastUsedColumn(oSheet) 'see functions below
nEndRow = getLastUsedRow(oSheet)
REM Then do as you please, e.g.
oCell=oSheet.getCellByPosition(nEndCol - 3 , nEndRow + 1)
oCell.value = dat
oCell=oSheet.getCellByPosition(nEndCol - 2 , nEndRow + 1)
oCell.Value = hab
oCell=oSheet.getCellByPosition(nEndCol - 1 , nEndRow + 1)
oCell.String = beschr
ThisComponent.CurrentController.Select(oCell)
End Sub
Function getLastUsedColumn(oSheet as Object) as Integer
Dim oCell As Object
Dim oCursor As Object
Dim aAddress As Variant
oCell = oSheet.GetCellbyPosition( 0, 0 )
oCursor = oSheet.createCursorByRange(oCell)
oCursor.GotoEndOfUsedArea(True)
aAddress = oCursor.RangeAddress
GetLastUsedColumn = aAddress.EndColumn
End Function
In der Tabelle passiert folgendes: Wenn in der Spalte Wert die Formel hinterlegt ist (hier durch xy symbolisiert) überspringt er die Zeile, was ja eigentlich logisch ist da in dieser Reihe ja etwas vorhanden ist. Genau das soll aber nicht passieren, da die Formel ja mit den Daten aus dem Formular atbeiten soll. d.h. der Cursor soll auf die erste freie Zeile in der ersten Spalte springen und dann meine Daten eintragen.
Datum Anzahl Position Wert
16.3.06 10 33103
xy
16.3.06 10 33103
Hallo Rainer,
das klappt nicht. Der Cursor landet immer noch in der Reihe nach dem letzten Eintrag.
Ich hab jetzt folgendes Makro:
[code]REM ***** BASIC *****
Private Sub OKButton_Click()
DIM dat As Date
DIM hab As Currency
DIM beschr As String
DIM oCell As Object
Dim oDoc As Object
Dim oSheet As Object
Dim oComboBox As Object
Dim oDateField As Object
Dim oCurrencyField As Object
Dim oCursor As Object
Dim nEndCol As Integer
Dim nEndRow As Integer
oDoc = ThisComponent
oSheet = oDoc.Sheets.GetByName("Formular")
oForm = oSheet.DrawPage.Forms.GetByName("Standard")
oDateField = oform.getByName("oDateFieldDatum")
dat = CDateFromIso(oDateField.date)
oSheet = oDoc.Sheets.GetByName("Formular")
oForm = oSheet.DrawPage.Forms.GetByName("Standard")
oCurrencyField = oform.getByName("oCurrencyFieldHaben")
hab = oCurrencyField.value
oSheet = oDoc.Sheets.GetByName("Formular")
oForm = oSheet.DrawPage.Forms.GetByName("Standard")
oComboBox = oform.getByName("oComboBoxBeschreibung")
beschr = oComboBox.text
oDocument=ThisComponent
oSheet = ThisComponent.Sheets.getByName( "Materialaufwand" )
nEndCol = getLastUsedColumn(oSheet) 'see functions below
nEndRow = getLastUsedRow(oSheet)
REM Then do as you please, e.g.
oCell=oSheet.getCellByPosition(nEndCol - 3 , nEndRow + 1)
oCell.value = dat
oCell=oSheet.getCellByPosition(nEndCol - 2 , nEndRow + 1)
oCell.Value = hab
oCell=oSheet.getCellByPosition(nEndCol - 1 , nEndRow + 1)
oCell.String = beschr
ThisComponent.CurrentController.Select(oCell)
End Sub
Function getLastUsedColumn(oSheet as Object) as Integer
Dim oCell As Object
Dim oCursor As Object
Dim aAddress As Variant
oCell = oSheet.GetCellbyPosition( 0, 0 )
oCursor = oSheet.createCursorByRange(oCell)
oCursor.GotoEndOfUsedArea(True)
aAddress = oCursor.RangeAddress
GetLastUsedColumn = aAddress.EndColumn
End Function
[/code]
In der Tabelle passiert folgendes: Wenn in der Spalte Wert die Formel hinterlegt ist (hier durch xy symbolisiert) überspringt er die Zeile, was ja eigentlich logisch ist da in dieser Reihe ja etwas vorhanden ist. Genau das soll aber nicht passieren, da die Formel ja mit den Daten aus dem Formular atbeiten soll. d.h. der Cursor soll auf die erste freie Zeile in der ersten Spalte springen und dann meine Daten eintragen.
Datum Anzahl Position Wert
16.3.06 10 33103
xy
16.3.06 10 33103