Macros to write specified cell values to specified cells (& clear them)
I need numerous ‘write’ and ‘clear’ buttons.
I recorded two macros.
The ‘clear’ code seems fine … enter the range, the dispatcher then: GoToCell - ClearContents
The ‘write’ code can fail because it copies and pastes.
If Write is used, and then Clear … it fails because the range is highlighted.
Hence I need something like this:
args1(0).Name = “Source”
args1(0).Value = “$sheet1.$A$3:$D$3”
args2(0).Name = “Target”
args2(0).Value = “$sheet2.$A$5:$D$5”
dispatcher.executeDispatch(… args2()=args1()
Such a code would allow me to simply change the two ranges, and rename the macro.
I guess it is simple but I can’t find any reference to it.
Can anyone help me with the code?
(I have just downloaded all of Jean-François Nifenecker’s guides, so hopefully I will learn)
Here is the recorded macro:
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 = "$A$3:$D$3"
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$5"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args3())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
end sub