Page 1 of 1
[Solved] Help with converting macro from Excel
Posted: Tue Dec 05, 2017 8:03 pm
by Przemyslav
Hello everyone. Could you help me to convert my macro from Excel to OpenOffice??
My macro:
Code: Select all
Sub copy()
Sheets("X").Range("A1:C10").Copy Sheets("Y").Range("A1")
Application.CutCopyMode = False
End Sub
This is simple macro to copy cells appearance and values.
Thank you very much
Re: Help with converting macro from Excel
Posted: Tue Dec 05, 2017 9:09 pm
by FJCC
Code: Select all
oSheetX = ThisComponent.Sheets.getByName("X")
oSheetY = ThisComponent.Sheets.getByName("Y")
oSource = oSheetX.getCellrangeByName("A1:C10")
oTarget = oSheetY.getCellrangeByName("A1")
oSheetY.copyRange( oTarget.CellAddress, oSource.RangeAddress)
I don't know what
means. My code just copies the cells.
Re: Help with converting macro from Excel
Posted: Tue Dec 05, 2017 11:33 pm
by Przemyslav
Thank you so much. It's working
Re: Help with converting macro from Excel
Posted: Wed Dec 06, 2017 12:10 am
by Lupp
FJCC wrote:I don't know what
means.
I don't know VBA or Excel. Just a guess: An Office application (component?) has a property controlling the general way a copy command is working: like Ctrl+C or like Ctrl+X. Assuming the posted Sub started with Application.CutCopyMode = True (Work like Ctrl+X!) it sets the Ctrl+C mode at its end.
In the Calc api the clearing of copied contents is controlled much more detailed:
Code: Select all
oSource.RangeAddress.ClearContents(CellFlags)
where Cellflags is a bit pattern passed as a Long integer.
See
https://api.libreoffice.org/docs/idl/re ... Flags.html .
You may also visit
https://api.libreoffice.org/docs/idl/re ... Flags.html .
@"Przemyslav": Don't use the forum in on-way mode. FJCC obyiously wanted to be told what the Application.CutCopyMode = False means, and surely I want. You will know. Let us know, too.
Editing: In the AOO/LibO Calc API there is also the
.moveRange method:
"After copying the contents of the cell range, all cells will be cleared."I hope, however, only the cells of the source range are cleared.