[Solved] Help with converting macro from Excel

Creating a macro - Writing a Script - Using the API

[Solved] Help with converting macro from Excel

Postby Przemyslav » Tue Dec 05, 2017 8:03 pm

Hello everyone. Could you help me to convert my macro from Excel to OpenOffice??

My macro:

Code: Select all   Expand viewCollapse view
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
Przemyslav
 
Posts: 2
Joined: Tue Dec 05, 2017 7:59 pm

Re: Help with converting macro from Excel

Postby FJCC » Tue Dec 05, 2017 9:09 pm

Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
Application.CutCopyMode = False

means. My code just copies the cells.
AOO 3.4 or 4.1 on MS Windows XP ( before 2013-08-03) or Windows 7
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 6157
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Help with converting macro from Excel

Postby Przemyslav » Tue Dec 05, 2017 11:33 pm

Thank you so much. It's working :)
OpenOffice 4.1.4 on Windows 10
Przemyslav
 
Posts: 2
Joined: Tue Dec 05, 2017 7:59 pm

Re: Help with converting macro from Excel

Postby Lupp » Wed Dec 06, 2017 12:10 am

FJCC wrote:I don't know what
Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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 5.4.2 and older versions, PortableOpenOffice 4.1.3 and older, StarOffice 5.2
---
Maybe we might! (Create a powerful UFO: United Free Office)
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 1521
Joined: Sat May 31, 2014 7:05 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 9 guests