Calc Copy Active cell macro

Is there a way to copy a value of a current active cell to clipboard?
What i have to do in 1 macro:

Copy active cell from “sheet2”
paste is into a specific cell in “sheet1”
Copy a different cell from “sheet1”
Paste it into original cell into “sheet2”

Bangin my head against the wall on that one. For the simple reason of being a noob i’m stuck on step 1. The rest of the macro is working. The only thing is when i select a new cell with a mouse and run the macro, the previously selected cell is still copied.

Insight greatly appreciated.

sub plus15
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 ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Nr"
args2(0).Value = 1

dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args2())

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

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 = "D"
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 = 4

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

rem ----------------------------------------------------------------------
dim args5(0) as new com.sun.star.beans.PropertyValue
args5(0).Name = "ToPoint"
args5(0).Value = "$D$8"

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

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

rem ----------------------------------------------------------------------
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "Nr"
args7(0).Value = 2

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

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

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


end sub`

You can’t modify parameters of a recorded macro by UI actions while it’s running.
The “other cell” from where you want to copy something in the second step, must be selected by predefined steps (GotoCell again or “Down 11” e.g.) in the “other sheet” during recording. If this can’t be done or isn’t sufficient for your needs, your problem may be a very fundamental (and non-trivial) one:
How to pass arguments to Subroutines.

Yeah, that much i figured. Thats why step2 cell stays always the same. What i basically tried to do is to take a value out of a cell, paste it somewhere hidden, perform sum on it and paste the result value back to original cell. It even does not have to be a different sheet if it complitates things.

For example:

Sub copy_active_cell()
	
	cc = ThisComponent.CurrentController
	sheet = cc.ActiveSheet
	source = cc.Selection
	
	If source.ImplementationName <> "ScCellObj" Then
		Exit Sub
	End If
	
	target = ThisComponent.Sheets.getByName("Sheet1").getCellRangeByName("D6")
	
	sheet.copyRange(target.CellAddress, source.RangeAddress)

End Sub

Look:
https://wiki.documentfoundation.org/Macros/Basic/Calc/Ranges#Copy

Thanks for the code, does it happen to have an option to be compatible with “paste special” Where it passes values only and not formulas?

Paste special is done with the .uno:InsertContents command.
The Flags property can contain a sequence of the following letters:
A: all; D: datetime; F: formula; N: cell note; O: object; S: string; T: formats; V: numbers.

Care: source and target must be cells.

target.Value = source.Value