Hi folks,
I am desperate. I am a translator. I have a database of translation jobs, I made myself a macro to generate two writer files from templates. The filenames are generated from data in a database. One file is just opened and stored under a new name, in the other I make some changes. In the first half of last year, until I updated Libreoffice to the latest version, the macro worked (some parts of the window went black, but LO was willing to cooperate). Now I am getting crashes (the file is stored, but every time I generate the files, I have to restart LO). I think I must have done something wrong, but I am stuck. Please, have a look. If this is not the way to go, how to achieve the goal?
Thanks in advance.
Here goes the macro, activated by a button in a form:
Sub GenerateFiles
Dim Doc As Object
Dim DocB As Object
Dim oDoc As Object
Dim oForms As Object
Dim oForm As Object
Dim GeneratorFormName As String
Dim SourcePath As String
Dim TranslationSourceFileUrl As String
Dim FormulaSourceFileUrl As String
Dim TranslationTargetFileUrl As String
Dim FormulaTargetFileUrl As String
Dim TranslationHeaderString As String
Dim SKFormulaString As String
Dim HUFormulaString As String
Dim YearString As String
Dim Dummy() 'An empty array of PropertyValues
Dim Dummy2() 'An empty array of PropertyValues
Dim DummyB() 'An empty array of PropertyVal.ues
Dim DummyB2() 'An empty array of PropertyValues
Dim TextFieldEnum As Object
Dim TextField As Object
Dim oProps as object
Dim oDocProps as object
dim s as string
UpdateFileNames() 'this updates TranslationFileNameField
GeneratorFormName = "GeneratorForm"
SourcePath = "file:///z:/pecset/2026/"
FormulaSourceFileUrl = SourcePath & "formulaSource.ott"
YearString = "/2026"
oForms = ThisComponent.DrawPage.Forms
if oForms.hasByName(GeneratorFormName) then
oForm = oForms.getByName(GeneratorFormName)
if oForm.getByName("FromSlovakToHungarianField").getCurrentValue() then
TranslationSourceFileUrl = SourcePath & "translationSourceHU.ott"
SKFormulaString = "z jazyka slovenského do jazyka maďarského"
HUFormulaString = "szlovák nyelvről magyar nyelvre"
else
TranslationSourceFileUrl = SourcePath & "translationSourceSK.ott"
SKFormulaString = "z jazyka maďarského do jazyka slovenského"
HUFormulaString = "magyar nyelvről szlovák nyelvre"
end if
REM translation file part
REM load template and save new document as set name
Doc = StarDesktop.LoadComponentFromURL(TranslationSourceFileUrl, "_default", 0, Dummy)
TranslationTargetFileUrl = oForm.getByName("TranslationFileNameField").getCurrentValue()
TranslationTargetFileUrl = Replace(TranslationTargetFileUrl,"/","-")
TranslationTargetFileUrl = Replace(TranslationTargetFileUrl,"\","-")
TranslationTargetFileUrl = Replace(TranslationTargetFileUrl,":","-")
TranslationTargetFileUrl = Replace(TranslationTargetFileUrl,";","-")
TranslationTargetFileUrl = SourcePath & TranslationTargetFileUrl
REM MsgBox "Translation part:" & TranslationTargetFileUrl
Doc.storeAsURL(TranslationTargetFileUrl, Dummy2)
REM formula file part
REM MsgBox "Formula"
REM load template
DocB = StarDesktop.LoadComponentFromURL(FormulaSourceFileUrl, "_default", 0, DummyB)
REM set values
oDocProps = DocB.getDocumentProperties()
oProps = oDocProps.UserDefinedProperties
REM MsgBox oProps.dbg_properties
REM MsgBox oProps.dbg_methods
oProps.setPropertyValue("Copies", oForm.getByName("CopiesField").getCurrentValue())
oProps.setPropertyValue("CustomerAddress", oForm.getByName("ClientAddressField").getCurrentValue())
oProps.setPropertyValue("CustomerNameHU", oForm.getByName("ClientNameHUField").getCurrentValue())
oProps.setPropertyValue("CustomerNameSK", oForm.getByName("ClientNameField").getCurrentValue())
oProps.setPropertyValue("DateOfExecution", oForm.getByName("ExecutionDateField").getCurrentValue())
oProps.setPropertyValue("DirectionHU", HUFormulaString)
oProps.setPropertyValue("DirectionSK", SKFormulaString)
oProps.setPropertyValue("DocID", oForm.getByName("JobIDField").getCurrentValue())
oProps.setPropertyValue("DocNumber", oForm.getByName("JobNumberField").getCurrentValue() & YearString)
oProps.setPropertyValue("OrderID", oForm.getByName("CaseIDField").getCurrentValue())
oProps.setPropertyValue("PagesOriginal", oForm.getByName("PagesOriginalField").getCurrentValue())
oProps.setPropertyValue("PagesTranslation", oForm.getByName("PagesTranslationField").getCurrentValue())
oProps.setPropertyValue("TitleFixedHU", oForm.getByName("SubjectFixedPartHUField").getCurrentValue())
oProps.setPropertyValue("TitleFixedSK", oForm.getByName("SubjectFixedPartSKField").getCurrentValue())
oProps.setPropertyValue("TitleVariable", oForm.getByName("SubjectVariablePartField").getCurrentValue())
REM store file
FormulaTargetFileUrl = oForm.getByName("TranslationFileNameField").getCurrentValue()
FormulaTargetFileUrl = Replace(FormulaTargetFileUrl,"/","-")
FormulaTargetFileUrl = Replace(FormulaTargetFileUrl,"\","-")
FormulaTargetFileUrl = Replace(FormulaTargetFileUrl,":","-")
FormulaTargetFileUrl = Replace(FormulaTargetFileUrl,";","-")
FormulaTargetFileUrl = SourcePath & "formula/formula - " & FormulaTargetFileUrl
DocB.storeAsURL(FormulaTargetFileUrl, DummyB2)
endif
End Sub