Share a Calc document via a macro, not manually via the GUI

Hi, all, am looking to share a calc document via a macro, as opposed to manually clicking “Tools/Share Spreadsheet”.

So far as manually sharing goes, have noticed that if the Tabbed Interface is selected, Share Spreadsheet no longer appears under Tools. One must apparently use the Standard Toolbar to even see Tools/Share Spreadsheet. Have verified this on WinDoze, Mac and 'nix versions of LO. Not sure if that’s a bug.

So far as sharing a document programmatically, have checked Andrew Pitonyak’s excellent docs but they don’t mention anything on the subject.

Did look for “share” in the source code; it returned > 20K hits. Found sharedocumentdlg.ui but it appears to be just implementing how “Tools/Share Spreadsheet” shows up in the menu. Found sharedocdlg.cxx but even assuming it’s the code that performs sharing, am not sure how to invoke it from a macro.

Have only found one other post on this subject here but it was unanswered.

The Dispatch Commands Page references the uno command for sharing, but it’s unclear how to implement it.

I know on various platforms I could use a scripting tool (such as AutoIT on WinDoze) and not even involve LO directly, but am interested in a more platform-independent method using a LO BASIC macro. (Will eventually port all the BASIC code I’ve written over to Python, but not today!)

If anyone has info on how to accomplish this, I would be most appreciative. Thanks!

Enable macro recording.
Start macro recording.
Call Tools>Share>Spreadsheet
Stop macro recording.
The resulting macro should be a dispatch.

Hi, thanks for your reply.

I did not try that becuase the other post on this subject specifically said recording a macro did not work as expected, and asked if there was another way to accomplish the task.

But based on your reply I tried anyway, and, unfortunately, recording also did not work for me, producing exactly the same code as the post, with the exception of my recording not having a dispatch to saving the document first before the share dispatch was invoked (guessing the OP saved the doc first when recording).

To be clear, the document shared via recording remained shared when re-opening, but running the resulting code on a new document - and examining ThisComponent first via a breakpoint in the macro editor to verify the correct doc was being referenced - did not result in the new doc being shared.

Also, using XRay, inspection of both the document and frame objects does not appear to show anything like a “sharing” method.

Any other insight would be most appreciated. Thanks!

Some recorded macros work as expected, some don’t, others have been recorded wrongly.
In your particular case, the recorded macro does exactly the same thing as the menu item you are missing in the tabbed user interface.

The macro recorder records dispatch commands.

Less than 30 seconds:

sub recorded_Share_Spreadsheet
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ShareDocument", "", 0, Array())


end sub

'k, except the recorded macro did not do “exactly the same thing”, as it did not activate the sharing.

Is there another method to try, or is there some way to determine other vars that may need to be passed to the dispatch?

I will note the “manual” way of doing it pops up other dialog boxes about saving, etc., so yes, it’s possible there’s more to do than just the recorded dispatch. Just don’t know what those other things may be.

I run the macro.
The same dialog pops up as if I had clicked Tools>Share Spreadsheet…
I click the check box to enable sharing if it was not shared or to disable sharing if it was shared.
When I run the same macro again I see the same dialog and toggle the sharing mode back to the other state.
This is exactly what happens when I click Tools>Share Spreadsheet…

P.S. Dispatches are view sensitive. You have to call the macro from the document frame, e.g. Tools>Macros or any UI element of the document’s active frame.
It does nothing when called from the IDE.