Close all opened Writer documents

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
xsintill
Posts: 1
Joined: Mon Mar 12, 2012 4:34 pm

Close all opened Writer documents

Post by xsintill »

I am trying to close all opened writer documents. I thought I had a solution but when i also had a calc spreadsheet open the code would close the opened spreadsheet also. How do i distinguish between components so i only close writer components. Code so far:

Code: Select all

var
  lComponents, lDocument: OleVariant;
begin
  lComponents := FDesktop.GetComponents.CreateEnumeration;
  while lComponents.hasMoreElements do
  begin
    lDocument := lComponents.NextElement;
    lDocument.Close(True);
  end;
end;
...
//FDesktop is created like so
FDesktop := FLibreOffice.createInstance('com.sun.star.frame.Desktop');
ooo 3.3
FJCC
Moderator
Posts: 9623
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Close all opened Writer documents

Post by FJCC »

Something like this (written in Basic) might work

Code: Select all

Enum = StarDesktop.getComponents.createEnumeration()
While Enum.hasMoreElements()
	Doc = Enum.nextElement()
	If Doc.Identifier = "com.sun.star.text.TextDocument" Then
		Doc.close(True)
	End If
WEnd
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Post Reply