' Opens a Document, checks beforehand, whether it has to be loaded
' or whether it is already on the desktop.
' If the parameter bDisposable is set to False then the returned document
' should not be disposed afterwards, because it is already opened.
Function OpenDocument(DocPath as String, Args(), Optional bDisposable as Boolean)
Dim oComponents as Object
Dim oComponent as Object
' Search if one of the active Components is the one that you search for
oComponents = StarDesktop.Components.CreateEnumeration
While oComponents.HasmoreElements
oComponent = oComponents.NextElement
If hasUnoInterfaces(oComponent,"com.sun.star.frame.XModel") then
If UCase(oComponent.URL) = UCase(DocPath) then
OpenDocument() = oComponent
If Not IsMissing(bDisposable) Then
bDisposable = False
End If
Exit Function
End If
End If
Wend
If Not IsMissing(bDisposable) Then
bDisposable = True
End If
OpenDocument() = StarDesktop.LoadComponentFromURL(DocPath,"_default",0,Args())
End Function
Sub UnprotectSheets(Optional oSheets as Object)
Dim i as Integer
Dim oDocSheets as Object
If IsMissing(oSheets) Then
oDocSheets = StarDesktop.CurrentFrame.Controller.Model.Sheets
Else
Set oDocSheets = oSheets
End If
For i = 0 To oDocSheets.Count-1
oDocSheets(i).Unprotect("")
Next i
End Sub