How do I check for all open soffice documents? I found out that if I use ThisComponent.Close(True) or ThisComponent.Dispose it leaves soffice.exe and soffice.bin processes running. If I use StarDesktop.Terminate(), it will shut down all processes, but it will also close all open documents.
If I use File>Exit or the close 'X' on the caption bar the processes shut down (this has got to be a bug). I will be more then glad to skip the previous question if anyone has an answer to this issue.
Thanks...
[Solved] How to enumberate documents?
[Solved] How to enumberate documents?
Last edited by grnhorn on Sun Aug 24, 2008 6:59 pm, edited 1 time in total.
OOo 2.4.X on Ms Windows XP
Re: How to enumberate documents?
Code: Select all
REM Basic
oEnum = StarDesktop.getComponents()
http://api.openoffice.org/docs/common/r ... Components
StarDesktop is a global helper variable in StarBasic similar to ThisComponent.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
[Solved] How to enumberate documents?
Thanks Villeroy, here is the final code I came up with. The only issue I found is that BasicIDE is included as a document.
Code: Select all
Sub TerminateProcesses()
Dim sDocURL As String
Dim oDocs As Object
Dim oDoc As Object
Dim oComponents As Object
' Close document
GlobalScope.BasicLibraries.LoadLibrary("Tools")
sDocURL = ThisComponent.getURL()
oDocs = StarDesktop.getComponents().createEnumeration()
Do While oDocs.hasMoreElements()
oDoc = oDocs.nextElement()
REM This line looks at the document you are working with and will terminate processes if nothing else is running;
REM otherwise it will close and leave the other running. 'Reverse "/" to get path without filename.
If oDoc.URL <> DirectoryNameoutofPath(sDocURL, "\") Then ThisComponent.Close(True)
REM This line can be used to determine how many documents are open.
'i = i + 1 'Counter
Loop
REM This shuts down all running documents and terminates all running soffice processes
StarDesktop.Terminate()
End Sub
OOo 2.4.X on Ms Windows XP