Close all opened Writer documents

Java, C++, C#, Delphi, ??? - Using the UNO bridges

Close all opened Writer documents

Postby xsintill » Thu Mar 22, 2012 11:38 am

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   Expand viewCollapse view
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
xsintill
 
Posts: 1
Joined: Mon Mar 12, 2012 4:34 pm

Re: Close all opened Writer documents

Postby FJCC » Thu Mar 22, 2012 6:29 pm

Something like this (written in Basic) might work
Code: Select all   Expand viewCollapse view
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
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7748
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA


Return to External Programs

Who is online

Users browsing this forum: No registered users and 2 guests