Sto incamminandomi nel mondo "Eventi" e ho buttato giù qualche istruzione:
Codice: Seleziona tutto
Sub NuovoDocumento()
const evento as string = "Evento nuovo documento "
on error goto errore
ctr = ctr +1
MsgBox evento & "di " & fdocumento & format(ctr,"(#0)")
on error goto 0
exit sub
errore:
MsgBox error$ & chr(13) & evento
resume next
on error goto 0
End Sub
Sub DocumentoCreato()
const evento as string = "Evento documento creato "
ctr = ctr +1
MsgBox evento & "di " & fdocumento & format(ctr,"(#0)")
on error goto 0
exit sub
errore:
MsgBox error$ & chr(13) & evento
resume next
on error goto 0
End Sub
Sub ApriDocumento()
const evento as string = "Evento Apri documento "
ctr = ctr +1
MsgBox evento & "di " & fdocumento & format(ctr,"(#0)")
on error goto 0
exit sub
errore:
MsgBox error$ & chr(13) & evento
resume next
on error goto 0
End Sub
Function fDocumento() As String
Dim oDocumento As Object
oDocumento = StarDesktop.CurrentComponent
If oDocumento.supportsService("com.sun.star.sheet.SpreadsheetDocument") Then
fDocumento = "Calc"
ElseIf oDocumento.supportsService("com.sun.star.text.TextDocument") Then
fDocumento = "Writer"
ElseIf oDocumento.supportsService("com.sun.star.presentation.PresentationDocument") Then
fDocumento = "Impress"
ElseIf oDocumento.supportsService("com.sun.star.drawing.DrawingDocument") Then
fDocumento = "Draw"
ElseIf oDocumento.supportsService("com.sun.star.sdb.OfficeDatabaseDocument") Then
fDocumento = "Base"
ElseIf oDocumento.supportsService("com.sun.star.formula.FormulaProperties") Then
fDocumento = "Math"
ElseIf oDocumento.supportsService("com.sun.star.script.BasicIDE") Then
fDocumento = "Sviluppo IDE"
Else
fDocumento = "Sconosciuto"
End If
fDocumento = fDocumento & Space(1)
End Function
Il titoli delle sub sono autodescrittivi. Ho abbinato le sub ai relativi eventi.
Se attivo LibreOffice e poi apro un qualsiasi file le sub sono richiamate correttamente (X lo meno la "ApriDocumento").
Se attivo Calc o Writer direttamente le applicazioni vanno in crash.
Ho disattivato gli eventi "Nuovo documento" e "Documento creato", lasciando solo il "Apri documento" e non ho problemi ne partendo da LibreOffice ne dalle singole applicazioni.
Ho ripetuto le stesse istruzioni in ambiente OpenOffice e, anche con la gestione dei tre eventi, aprendo direttamente Calc non ho problemi.
Qualcuno ha esperienze in merito? Ringrazio anticipatamente.