Calc: Weird copy-paste macro issue...

Macro script wired to a button.

When button is pressed a block of cells is copied and paste-inserted to another part of the same page.

At the end of the script an empty cell is clicked to clear any highlighting.

Everything works as it should.

Until you close the doc.ots and reopen.

Now the button isn’t working.

The page kinda flickers but nothing happens.

A work around is to highlight and copy the block in question, then click the button.

Which fixes the problem.

And, the button works every time after that.

Close and re-open the doc.ots.

Now it’s back to the start with the button not working.

REM  *****  BASIC  *****
    
sub Main
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 ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$J$15:$N$27"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "ToPoint"
args3(0).Value = "$A$15"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args3())

rem ----------------------------------------------------------------------
dim args4(5) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Flags"
args4(0).Value = "A"
args4(1).Name = "FormulaCommand"
args4(1).Value = 0
args4(2).Name = "SkipEmptyCells"
args4(2).Value = false
args4(3).Name = "Transpose"
args4(3).Value = false
args4(4).Name = "AsLink"
args4(4).Value = false
args4(5).Name = "MoveMode"
args4(5).Value = 0

dispatcher.executeDispatch(document, ".uno:InsertContents", "", 0, args4())

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:TerminateInplaceActivation", "", 0, Array())

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:Cancel", "", 0, Array())

rem ----------------------------------------------------------------------
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "ToPoint"
args7(0).Value = "$J$15"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args7())


end sub

sounds a little like Calc: Is there some known issues using button to execute a macro - II? … pls. check …