[Solved] Help with converting macro from Excel

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Przemyslav
Posts: 2
Joined: Tue Dec 05, 2017 7:59 pm

[Solved] Help with converting macro from Excel

Post 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 :)
Last edited by Hagar Delest on Sun Dec 10, 2017 11:14 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 4.1.4 on Windows 10
FJCC
Moderator
Posts: 9277
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Help with converting macro from Excel

Post 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

Code: Select all

Application.CutCopyMode = False
means. My code just copies the cells.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Przemyslav
Posts: 2
Joined: Tue Dec 05, 2017 7:59 pm

Re: Help with converting macro from Excel

Post by Przemyslav »

Thank you so much. It's working :)
OpenOffice 4.1.4 on Windows 10
User avatar
Lupp
Volunteer
Posts: 3552
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Help with converting macro from Excel

Post by Lupp »

FJCC wrote:I don't know what

Code: Select all

Application.CutCopyMode = False
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.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Post Reply