While macros is running it tries to open some file. But an error arises if this file is already open. How can I check in macros if this file is already open?
Just a demo. Inspect the components managed by the StarDesktop.
Sub inspectComponents()
theComponents = StarDesktop.Components
theCEnum = theComponents.CreateEnumeration
Do While theCEnum.HasMoreElements
oneComponent = theCEnum.NextElement
MsgBox(oneComponent.Title & Chr(10) & oneComponent.URL)
Loop
End Sub
Unsaved components have an empty URL. The BASIC IDE also has no URL, of course. There may be additional specifics I don’t know.
Just use function OpenDocument from library Tools:
' 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.
GlobalScope.BasicLibraries.LoadLibrary("Tools")
oDoc = OpenDocument(ConvertToURL(sFileName), loadArgs, bDisposable)
... do something
if bDisposable then oDoc.Close(True)