[Solved] Change cursor position from File 1 to File 2

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Math
Posts: 89
Joined: Mon Oct 29, 2018 6:32 pm

[Solved] Change cursor position from File 1 to File 2

Post by Math »

I need a macro that changes the cursor position from File 1 to File 2, that is, jump from file 1 to file 2 .

                   I'm trying to use the code suggested by mr. FJCC in topic: viewtopic.php?f=45&t=87507

                   but "NO" is working for me.

                   Did I do something wrong?

           Note:

           1) the two files (1 and 2) are already open

           2) the new cursor position should go to File 2, in Sheet3, in cell D2



hugs.
Last edited by Math on Tue Nov 13, 2018 5:43 pm, edited 1 time in total.
LibreOffice 5.4.4.2 on Windows 7
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Change cursor position from File 1 to File 2

Post by Zizi64 »

I suggest you: If you want control more than one document - by your macro, then it is better to place the macro routines into the MyMacros/Standard library, instead of the documents. Then you will able to control all of the documents, what you can get by the macro.
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.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Change cursor position from File 1 to File 2

Post by Villeroy »

Possibly you don't have to do this. You can manipulate the document programmatically without any focus anywhere as long as the document is loaded.

Code: Select all

OtherDoc = StarDesktop.loadComponentFromURL(url, "_default", 0, Array)
sh = OtherDoc.Sheets.getByName("Sheet3")
cell = sh.getCellByPosition(3, 1)
This gets a reference OtherDoc, loading the document if needed.
Now you can do anything you want with the cell, the sheet, the document without using any cursor at all.

If you want to show something to the user by selecting the cell in that document:

Code: Select all

view = OtherDoc.getCurrentController()
frame = view.getFrame()
win = frame.getContainerWindow()
frame.activate() 'frame takes focus now
win.toFront() 'visibly on top
view.setActiveSheet(sh) 'activate sheet
view.select(cell) 
https://wiki.openoffice.org/wiki/Docume ... nvironment

And yes, listen to what Zizi64 says. A global macro may be the better design choice in this case.
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
Math
Posts: 89
Joined: Mon Oct 29, 2018 6:32 pm

Re: Change cursor position from File 1 to File 2

Post by Math »

thank you very much mr. Villeroy, your macro worked perfectly .

also thank mr. Zizi64 by contribution .


hugs.
LibreOffice 5.4.4.2 on Windows 7
Post Reply