Copying data from sheet to another using push button

Creating a macro - Writing a Script - Using the API

Copying data from sheet to another using push button

Postby jeevanthara » Wed Sep 18, 2019 1:19 pm

Hi,
I'm new in OpenOffice Calc and i have a issue

I'm writing a macro that copy a value in a cell and paste that value in a range of cell of another sheet.

I got this code from Openoffice program.

Code: Select all   Expand viewCollapse view
Sub Main
Doc = ThisComponent
   Sheets = Doc.Sheets()
   SheetCopy = Sheets.getByName("SUM")
   SheetPaste = Sheets.getByName("data")
   CopyRange = SheetCopy.getCellRangeByName("C2:C10")
   PasteRange = SheetPaste.getCellRangeByName("B1:B9")
   PasteRange.DataArray = CopyRange.DataArray


End Sub


The above code works fine but it has certain problems. I want paste value to sheet named "Data" with range from a1:k1. But when i tried to replace
PasteRange = SheetPaste.getCellRangeByName("a1:k1")

Error pops up.
Open Office 14.1.6

Ubuntu 12.1.14
jeevanthara
 
Posts: 11
Joined: Tue Jul 30, 2019 12:31 pm

Re: COPYING DATA FROM SHEET TO ANOTHER USING PUSH BUTTON

Postby Villeroy » Wed Sep 18, 2019 2:34 pm

If you can not program, this should work with a recorded macro. although I can program, I would always do this manually.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: COPYING DATA FROM SHEET TO ANOTHER USING PUSH BUTTON

Postby JeJe » Wed Sep 18, 2019 2:47 pm

Here is how to transpose row to column. If you run the macro recorder as suggested above while following the instructions by FJCC here:

viewtopic.php?f=9&t=17334
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 624
Joined: Wed Mar 09, 2016 2:40 pm

Re: COPYING DATA FROM SHEET TO ANOTHER USING PUSH BUTTON

Postby jeevanthara » Thu Sep 19, 2019 10:21 am

Thanks a lot. I did as you told me.
Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****


sub Main
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 ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$C$2:$C$12"

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

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

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

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

rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "ToPoint"
args4(0).Value = "$A$2:$K$2"

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

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

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


end sub



I face an issue here. Every time I click push button the previous value get replaced by the new value. I need to save the value just like a table like one below the other. It would be very helpful to me
Open Office 14.1.6

Ubuntu 12.1.14
jeevanthara
 
Posts: 11
Joined: Tue Jul 30, 2019 12:31 pm

Re: COPYING DATA FROM SHEET TO ANOTHER USING PUSH BUTTON

Postby JeJe » Thu Sep 19, 2019 11:11 am

You need to change the column/row values...

args1(0).Value = "$C$2:$C$12"

... to whatever you want next then. Something like

col1 = 2 + n
col2 = 12 + n

args1(0).Value = "$C$" & col1 & ":$C$" & col2

n=n+1

Where n is the number of times you pushed the button and can be declared at the top of the module as a global variable.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 624
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: MSN [Bot] and 10 guests