Help with the worlds most basic copy & paste loop

Creating a macro - Writing a Script - Using the API

Help with the worlds most basic copy & paste loop

Postby JackWills » Mon Mar 20, 2017 10:45 pm

Hi world,

I am well and truly new to the wonderful world of OpenOffice Macros and I require some level 1 advice.

I am very simply trying to do this: Copy Cell A2, Paste into B2, Copy results in C2 (Which contains a formula based on B2 as one of the inputs), Paste in D2 as Value.. then loop 5 times.

If I was in VBA it would look like:

Dim n As Integer
For n = 2 to 5

Range("A" & n).Select
Selection.Copy
Range("B" & n).Select
ActiveSheet.Paste
Range("C" & n).Select
Selection.Copy
Range("D" & n).Select
Selection.PasteSepcial Paste:=xlPasteValues

Next n

Can anyone please help translate this into the simplest of terms? Once again I apologies for being such a novice, I am very new to this but understand the time savings this could make!

I have tried a few times but I am not sure ("Column" & n) works in openoffice? And I've read that you shouldn't have an "args" within a loop, which begs the question how does one do it in this circumstance!

Thank you again,

Jack J
JackWills
 
Posts: 3
Joined: Mon Mar 20, 2017 10:30 pm

Re: Help with the worlds most basic copy & paste loop

Postby karolus » Tue Mar 21, 2017 12:13 am

Hallo

Code: Select all   Expand viewCollapse view
def stupid_copy_paste():
    
doc XSCRIPTCONTEXT.getDocument()
    
sheet doc.CurrentController.ActiveSheet
    rrange 
sheet.getCellRangeByName
    
for sourcetarget in [('A2:A5''B2:B5'), ('C2:C5''D2:D5')]:
        
rrange(target).DataArray rrange(source).DataArray
AOO4, Libreoffice - 5.1 … 5.3.2.2 on Linux Mint17
User avatar
karolus
Volunteer
 
Posts: 843
Joined: Sat Jul 02, 2011 9:47 am

Re: Help with the worlds most basic copy & paste loop

Postby JackWills » Tue Mar 21, 2017 12:19 am

Hi Karolus, thanks for the reply!

I am afraid it is not as simple as copying them together.. I have simplified in my question but essentially B2 is an input for an extremely large engine in the background which final output is linked in row C. Therefore I can't simply copy all of A2:A5 into B2:B5 and instead it requires a loop so as to place B2 into the engine, computes the result in the engine and links to C2 then copies as values into D2 and then repeats for row 3.

Hope this makes sense, thanks for the help so far.
Open Office 3 on Windows 10
JackWills
 
Posts: 3
Joined: Mon Mar 20, 2017 10:30 pm

Re: Help with the worlds most basic copy & paste loop

Postby JackWills » Tue Mar 21, 2017 12:24 am

As an update I have tried experimenting with Record Macro and applied some VBA knowledge.

"Dim n as Integer
For n= 2 to 5

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "A" & n

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

next n"

This is the start of what I am trying to build as it is what selects "A2" (will build on with copy/pastes once I've worked this first part out).

I am getting the following error:

BASIC run-time error.
An exception occurred.
Type: com.sun.star.lang.IllegalArgumentException
Message: sequence element is not assignable by given value!
Open Office 3 on Windows 10
JackWills
 
Posts: 3
Joined: Mon Mar 20, 2017 10:30 pm

Re: Help with the worlds most basic copy & paste loop

Postby JeJe » Tue Mar 21, 2017 1:58 am

Put this before the for loop
dim args1(0) as new com.sun.star.beans.PropertyValue
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 114
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 8 guests