I've found examples for XModifyListener for Calc. Unfortunately I can't just simply copy them and the changes I made don't seem to work.
In my document I have 2 user-defined fields. One is the invoice number and one is date. I want to take the invoice number, modify the string and fill the date field. I did that successfully. Now I want to listen for changes of the invoice number field and run the macro.
This is how far I got, unfortunately it doesn't work.
Code: Select all
REM ***** BASIC *****
Global oListener as Object
Global InvoiceNumberField as Object
Global InvoiceDateField as Object
Sub Main
InvoiceNumberField = thisComponent.getTextFieldMasters().getByName("com.sun.star.text.FieldMaster.User.Rechnungsnummer")
InvoiceDateField = thisComponent.getTextFieldMasters().getByName("com.sun.star.text.FieldMaster.User.Datum")
oListener = createUnoListener("Modify_","com.sun.star.util.XModifyListener")
InvoiceNumberField.Content.addModifyListener(oListener)
End Sub
Sub Modify_modified(oEv)
updateDate()
End Sub
Sub Modify_disposing(oEv)
End Sub
Sub RmvListener
InvoiceNumberField = thisComponent.getTextFieldMasters().getByName("com.sun.star.text.FieldMaster.User.Rechnungsnummer")
InvoiceNumberField.removeModifyListener(oListener)
End Sub
Sub updateDate
InvoiceNumberField = thisComponent.getTextFieldMasters().getByName("com.sun.star.text.FieldMaster.User.Rechnungsnummer")
InvoiceDateField = thisComponent.getTextFieldMasters().getByName("com.sun.star.text.FieldMaster.User.Datum")
InvoiceDateField.Value = DateSerial(Mid(InvoiceNumberField.Content, 3, 4), Mid(InvoiceNumberField.Content, 7, 2), Mid(InvoiceNumberField.Content, 9, 2))
ThisComponent.TextFields.refresh
End Sub