[Solved] Macros don't work if open file B with macro button

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] Macros don't work if open file B with macro button

Post by Math »

Greetings,

                         I have an A.ods file with macro buttons.

                         Clicking on one of the buttons will open a B.ods file (which also contains macros).

                         if you try to use the buttons in the B file (which was opened with macro), then the macro buttons in file B do not work.

                         but if I have file A open and I manually open file B, then the macro buttons of file B work yes.
                         
                         if I do not have file A open, ie just open file B manually, then the macro buttons of file B work yes.

                         the problem is when I have file A open and I press the button to open file B, then the macros in file B do not work.

      comments:

     1) I am using the following BASIC code in file A to open file B:

                     Dim oDoc As Object
Dim sUrl As String
Dim Prop(0) as New com.sun.star.beans.PropertyValue
Dim document as object
Dim dispatcher as object

sUrl = convertToURL("C:\Users\Calc\Documents\Testes\arquivadas\Analisados.ods")

if fileExists(sUrl) then
oDoc = stardesktop.LoadComponentFromURL(sUrl, "_blank",0, Prop())
else
msgbox "Not found"
end if

  
    2) Opening the file B manually explodes the following message:
   
    This file contains links to other files. Do you want them updated?

    so I squeeze NO, because I'm just doing tests.


3) I want to automatically return to file A after opening file B with macro. How can I do this command?


   thank you very much.
Last edited by robleyd on Fri Nov 09, 2018 1:02 pm, edited 2 times in total.
Reason: Add green tick [robleyd, Moderator]
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: Macros do not work if you open file B with macro button

Post by Zizi64 »

Use two variables (oDocA and oDocB) for the two documents. You must get the two documents in one macro session. When the session (routine) is ended, the connection to between the documents and the variables will be lost.

(Or: you can try to use GLOBAL variables for the two documents...)
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.
Math
Posts: 89
Joined: Mon Oct 29, 2018 6:32 pm

Re: Macros do not work if you open file B with macro button

Post by Math »

Greetings Zizi64,

                 could you please make a practical example for me, I am a new user of the Basic Open Office Language.

                 I tried using the BASIC command from the following link:

                 https://wiki.openoffice.org/wiki/EN/Man ... kingConOOo / WorkingwithDocuments # Browsing.2C_guarding_and_coming_documents

                 The B file is opening perfect with the BASIC command displayed in the Link ..., but the macros in the B file still do not work.

                 The biggest problem is that when opening file B with the BASIC command, the following message is NOT "exploding" in the dialog box:

                 * This file contains links to other files. Do you want them updated ? *

                 when opening File B through the BASIC command, the message quoted must "explode" in a dialog box on the screen of File B ... but it is NOT "exploding".

                 it only "explodes" the message If I open file B "manually".


                 it is necessary that:

                 When I open file B with the BASIC command, it should also "explode" on the screen of File B, a dialog box with the message quoted above.



thank you very much
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: Macros do not work if you open file B with macro button

Post by Zizi64 »

https://wiki.openoffice.org/wiki/EN/Man ... kingConOOo / WorkingwithDocuments # Browsing.2C_guarding_and_coming_documents
The linked page have not contain any useful information

could you please make a practical example for me,
Please upload your "A" and "B" documents with the embedded macros.


How you want to call/launch the macros located in the document "B"?
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.
Math
Posts: 89
Joined: Mon Oct 29, 2018 6:32 pm

Re: Macros do not work if you open file B with macro button

Post by Math »

I did some tests with C and D files. It worked perfectly the test with the files C and D.

But when I ran the test with file A and B, the macros of file B do not work.

in the test with files A and B, it does not "explode" the record in the File B dialog box.

it is necessary that the message in the File B dialog box "explode" in the B file screen.

If this occurs, input will work the macros of the B file.


referring to the Link to open the B file, I am using:

https://wiki.openoffice.org/wiki/ES/Man ... documentos


hugs.
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: Macros do not work if you open file B with macro button

Post by Zizi64 »

Sorry, i can not help you without the specific sample files "A" and "B"...
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.
Math
Posts: 89
Joined: Mon Oct 29, 2018 6:32 pm

Re: Macros do not work if you open file B with macro button

Post by Math »

sr. Zizi64,

                 I am working inside a company server with LibreOffice 5.4.4.2.

                 when I press a button on File A to open File B, then it opens correctly.

                 the problem is that it does NOT "explode" the message for Link Updating in File B.

                 is attached a photo of the message that should "explode", but this message does NOT appear when I press the File A button.

                 see the attachment, is a photo that should appear when you open File B, but it does NOT appear.

                 if I manually open File B, then the message "explodes" yes.

                 so the macro buttons in File B do not work, why not "explode" the dialog box "with the message.

                 see the attached photo ...
Attachments
dialog box.jpg
LibreOffice 5.4.4.2 on Windows 7
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: Macros do not work if you open file B with macro button

Post by musikai »

You could use the shell to open the file:

Code: Select all

sUrl = convertToURL("C:\Users\Calc\Documents\Testes\arquivadas\Analisados.ods")
if fileExists(sUrl) then
oSyShell = CreateUnoService("com.sun.star.system.SystemShellExecute")
oSyShell.execute(sUrl , "", 0)
else
msgbox "Not found"
end if
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
FJCC
Moderator
Posts: 9277
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Macros do not work if you open file B with macro button

Post by FJCC »

An old thread that ends with this post says there is no API method to update links but there is a dispatcher call. The trick would be, I think, to create the dispatcher from the second document, something like

Code: Select all

documentB   = oDocB.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(documentB, ".uno:UpdateTableLinks", "", 0, Array()
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.
Math
Posts: 89
Joined: Mon Oct 29, 2018 6:32 pm

Re: Macros do not work if you open file B with macro button

Post by Math »

Greetings,

           I have not yet tested the solution suggested by mr. FJCC, but I inform you that the solution indicated by sr. Musikai worked perfectly.

           now it is already "exploding" the dialog box with the message.


Many thanks to all for the help.
LibreOffice 5.4.4.2 on Windows 7
Post Reply