[Solved] Switching between open oo documents

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
coonyp
Posts: 4
Joined: Wed Jul 22, 2009 7:59 pm

[Solved] Switching between open oo documents

Post by coonyp »

I am looking for the equivalent of the "Activate" method in VBA. Does anyone have some sample code? Thanks in advance.
Last edited by Hagar Delest on Sat Aug 15, 2009 3:33 pm, edited 1 time in total.
Reason: Tagged as solved
OOo 2.3.X on Ms Windows XP + Ms Windows Vista
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Switching between open oo documents

Post by acknak »

[Moved to Macros and UNO API]

Will most people here know what the "activate" function in VBA does?

If not, it might help to give a short description, or pointer some docs, to describe what it does, or tell us what you're trying to accomplish.
AOO4/LO5 • Linux • Fedora 23
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Switching between open oo documents

Post by rudolfo »

As far as I know the activate method in VBA was typically only used by the macro recorder of MS. In the same way as the macro recorder filled the recorded code with quite a lot of .Select methods. ("Activate a cell, a sheet or a document with a mouse click or with the cursor")
In the most macros that I was using I removed this kind of code because for macro writing it is enough if you have a reference to the sheet or document object. And typically you get this reference by looking into the collections.

I assume you need this for Calc (if you need it for Writer or another app you'd better specify in your post):

ThisComponent.Sheets.GetByName("Table1")
ThisComponent.Sheets.GetByIndex(0)

Counting for getByIndex starts at zero.

And I think a short form ThisComponent.Sheets(0) is also possible.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
coonyp
Posts: 4
Joined: Wed Jul 22, 2009 7:59 pm

Re: Switching between open oo documents

Post by coonyp »

Thank you for your responses.

I am actually working with Writer at the moment. In VBA (MSWord), the "activate" method could be used to switch between open documents. It would both allow the code to manipulate the document and would also activate the window of the specified document for the user. My typical use would be to create or open a document with code, assign an object variable to the document (i.e. set Doc1=ActiveDocument), then open a second document and assign a variable (Doc2) in the same manner. I then could switch between the two documents, i.e. Doc1.Activate. That would make Doc1 visible again just as if I had clicked it on the taskbar. So some code that would accomplish this with Open Office Writer would be greatly appreciated.
OOo 2.3.X on Ms Windows XP + Ms Windows Vista
coonyp
Posts: 4
Joined: Wed Jul 22, 2009 7:59 pm

Re: Switching between open oo documents

Post by coonyp »

I think I found the equivalent method. It is setFocus() and toFront() The tricky part how to define the document variable. The correct syntax for Writer is ThisComponent.CurrentController.Frame.ContainerWindow

So my sample code is as follows:
dim doc1, doc2
dim url as string
'Assign doc1 to current document
doc1 = ThisComponent.CurrentController.Frame.ContainerWindow
'Load blank document
url = "private:factory/swriter"
doc2 = StarDesktop.loadComponentFromURL(Url, url, 0, Dummy)
'Assign doc2 to new document
doc2 = ThisComponent.CurrentController.Frame.ContainerWindow
'Switch back to doc1
doc1.tofront()
doc1.setfocus()
OOo 2.3.X on Ms Windows XP + Ms Windows Vista
sreegowri
Posts: 1
Joined: Tue Oct 13, 2009 4:01 pm

Re: [Solved] Switching between open oo documents

Post by sreegowri »

Hi,

I am trying to switch between two open office documents, which I am not able to achieve.In one of the document there are two macros one for resetting all the fields and other for exiting. This works fine when opened individually.

I am able to open the second document using first open office document(using macros) .But macros doesn't work in the second document.Tried setfocus() and tofront() as mentioned but didn't work. I am trying this on Fedora 9.0.

Could you please let me know how to solve this issue.

Thanks in advance
Sree
openoffice 2.4 installed on Fedora 9.0
Post Reply