The args1 variable does not know any nothing about the document. It is freshly created. To be able to toggle the state with respect to any property, you need either access to the property itself or a method accessing it. As I do not know a path to the needed information, I have to create a global Boolean variable and to toggle its value every time the Sub made for toggling the state is called. Using my global variable to set Args1(1), the uno command called by the dispatcher will also toggle the addressed property.
(Editing. Addendum. Rectification)
(That the args variables used by uno commands neither do remember a previous setting nor do know anything about the document’s state remains true!)
My previously published solution and the example were based on the assumption that the uno command ‘ShowTrackedChanges’ was named “unmisguiding” and actually evaluates the args parameter. Playing with the solution the OQ posted in his self-answer I found that this is not the case.
The args parameter is treated by “.uno:ShowTrackedChanges” as a dummy without any evaluation. The mentioned uno command itself is toggling the state and thus should better be named ‘ToggleShowingTrackedChanges’.
Code to achieve the task is therefore very simple:
sub ShowHideChanges
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
REM Needed only to fill a syntactically mandatory parameter place:
dim args1(0) as new com.sun.star.beans.PropertyValue
dispatcher.executeDispatch(document, ".uno:ShowTrackedChanges", "", 0, args1())
end sub
I removed the code based on my misunderstanding.