Ask Your Question

How to know if some file is already open [closed]

asked 2017-08-03 18:38:24 +0200

shma_lo gravatar image

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?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by shma_lo
close date 2017-08-23 03:09:18.459346

2 Answers

Sort by » oldest newest most voted

answered 2017-08-03 19:04:23 +0200

Lupp gravatar image

updated 2017-08-03 19:08:15 +0200

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)
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.

edit flag offensive delete link more

answered 2017-08-03 20:41:21 +0200

JohnSUN gravatar image

updated 2017-08-03 20:42:08 +0200

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.
        oDoc = OpenDocument(ConvertToURL(sFileName), loadArgs, bDisposable)
    ... do something
        if bDisposable then oDoc.Close(True)
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-08-03 18:38:24 +0200

Seen: 67 times

Last updated: Aug 03 '17