[Solved] Switching between Calc and Writer Windows

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sanmahaan
Posts: 12
Joined: Wed May 10, 2017 3:53 pm

[Solved] Switching between Calc and Writer Windows

Post by sanmahaan »

Hello,
I wish to switch between the open documents window of CALC and WRITER using macros in libreoffice.
I have searched for quite a while, but am not even close.
I have a big list of things to do after this step.
Request the code for the same.
Thanks in advance.
Last edited by sanmahaan on Fri May 12, 2017 4:05 pm, edited 1 time in total.
Libreoffice 4.0.2.2 on LINUX
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Switching between Calc and Writer Windows

Post by Villeroy »

sanmahaan wrote: I have a big list of things to do after this step.
And you are going to ask us for every little item on that list? Forget it.
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
sanmahaan
Posts: 12
Joined: Wed May 10, 2017 3:53 pm

Re: Switching between Calc and Writer Windows

Post by sanmahaan »

Dear Villeroy...I have seen your helpful responses in many posts...was expecting an extension of the same.
I am trying very hard to implement my ideas in Libreoffice, which I have had to switch over to recently, and trying to solve things myself.. (The big list is for me ! ) .
Also will be thankful if someone could suggest some study materials
to understand the syntax of the despatchers, UNO, et al.
Hope for helpful responses from this forum for my genuine requests.
Libreoffice 4.0.2.2 on LINUX
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Switching between Calc and Writer Windows

Post by Zizi64 »

I wish to switch between the open documents window of CALC and WRITER using macros in libreoffice.
It is depend on the fact, how you opened those documents. If you open the documents by macro, then you can use the references

Code: Select all

oDoc_A = stardesktop.loadComponentFromURL(sURL_1,"_blank",0,array()
oDoc_B = stardesktop.loadComponentFromURL(sURL_2,"_blank",0,array()
what you used at the opening procedure.
viewtopic.php?f=45&t=59932

You can activate one or other document by the

Code: Select all

StarDesktop.setActiveFrame(...
API function. See the code snippets on the linked forum-page.

You MUST study the API (Application Programming Interface) functions.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
sanmahaan
Posts: 12
Joined: Wed May 10, 2017 3:53 pm

Re: Switching between Calc and Writer Windows

Post by sanmahaan »

Thank you Zizi64..Based on your input code and the links, I was able to work out and resolve my issue. Thanks once again.
Libreoffice 4.0.2.2 on LINUX
User avatar
Sébastien C
Posts: 111
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

Re: [Solved] Switching between Calc and Writer Windows

Post by Sébastien C »

Hello everybody
Zizi64 wrote:[...] If you open the documents by macro [...]
You can have some document opened by hand.
Open some documents.
Try this code bellow.
Enjoy!
:D

Code: Select all

Sub activateOpenFiles As String
 Dim fileName(255) As String
 Dim    files(255) As Object
 Dim   myDocuments As Object, theCollection As Object
 Dim     activate As Integer,             i As Integer, j As Integer

 theCollection = starDesktop.components.createEnumeration
             i = 0
      activate = 0

 On Error Goto Next_1:                                                     ' In order to avoid pseudos empty windows.
 While theCollection.hasMoreElements
  myDocuments = theCollection.nextElement
                                                                           ' Avoids the macro IDE and help windows.
  If ((  len(myDocuments.url    ) <> 0                     ) And _
      ( left(myDocuments.url, 20) <> "vnd.sun.star.help://") _
     ) Then
             i = i + 1
      files(i) = myDocuments
   fileName(i) = convertFromUrl(myDocuments.url)

   Next_1:
  End If
 Wend

 If (i >= 0) Then                                                          ' The opposite happens when no file is opened.
  Redim Preserve fileName(i)                                               ' Resize the table.
  For j = 1 to i
   If msgBox ("Activate:" & chr(13) & fileName(j), 36, "Activation") = 6 Then
    activate = j
    Exit For
   End If
  Next j
 End If

 If activate Then files(activate).currentController.frame.getContainerWindow.setFocus
End Sub
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 :ouch: .
Post Reply