Turning on change tracking with a macro in calc

I have a macro that is supposed to open an excel spreadsheet and enable change tracking. oDoc is the spreadsheet.args1() is a com.sun.star.beans.PropertyValue

The line

dispatcher.executeDispatch(oDoc, ".uno:TrackChanges", "", 0, args1())

Throws the error:

BASIC runtime error.
An exception occurred
Type: com.sun.star.lang.IllegalArgumentException
Message: cannot coerce argument type during corereflection call:
arg no.: 0 expected: “com.sun.star.frame.XDispatchProvider” actual: “com.sun.star.lang.XComponent”.

Is what I’m trying to do even possible? I’ve used this approach before with Writer documents.

I agree fully with @elmau. It is worth mentioning, though, that the system records a macro as:

sub Track
dim document   as object
dim dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "TraceChangeMode"
args1(0).Value = true
dispatcher.executeDispatch(document, ".uno:TraceChangeMode", "", 0, args1())
end sub

Notice “TraceChangeMode,” not “TrackChanges”. Also notice with some humor how redundant it is to pass TraceChangeMode to TraceChangeMode–not that there could be no reason.

It is better to use, almost always, the methods and properties of the objects.

ThisComponent.RecordChanges = True
1 Like