Calc: Weird copy-paste macro issue...

asked 2020-02-06 17:43:39 +0200

tuk gravatar image

updated 2020-08-11 17:57:30 +0200

Alex Kemp gravatar image

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
edit retag flag offensive close merge delete

Comments

sounds a little like https://ask.libreoffice.org/en/questi... ... pls. check ...

newbie-02 gravatar imagenewbie-02 ( 2020-08-24 04:27:28 +0200 )edit