I am adding to this thread because in this original post one element I don’t think was clearly shared was that this is to copy/paste three cells from the main spreadsheet (main.ods) to another spreadsheet (Summary.ods).
The need is still true for the advancing content one row in the Summary.ods sheet as shared in the original post, think I can make this happen with help offered below once I have a successful copy/paste to (Summary.ods) spreadsheet from (main.ods)
I am aware that other methods than “copyRange” must be used to copy data between different documents in this case (main.ods) and (Summary.ods).
Below is what I have for copying and pasting into a new spreadsheet.
It produces the “BASIC runtime error. Object variable not set.”
I have tried numerous things to set the “oDoc2” variable that is currently commented out in the macro below.
This line causing error - rng = oDoc2.Sheets(0).getCellRangeByName("A1:A3")
Sub test
Dim oDoc1
Dim oDoc2
Dim oSheets
Dim oSheet
oDoc1 = Thiscomponent
'oDoc2 = "c:\Summary.ods"
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oFrame1 = oDoc1.CurrentController.Frame
oSheet = oDoc1.Sheets(0)
rng = oSheet.getCellRangeByName("AP25:AR25")
oDoc1.CurrentController.Select(rng)
oDispatcher.executeDispatch(oFrame1, ".uno:Copy", "", 0, Array())
rng = oDoc2.Sheets(0).getCellRangeByName("A1:A3")
oDoc2.CurrentController.Select(rng)
oFrame2 = oDoc2.CurrentController.Frame
oDispatcher.executeDispatch(oFrame2, ".uno:Paste", "", 0, Array())
End Sub
Original Post
I am hoping someone can lead me to a sample of the following
I am wanting to copy content (with a button) from 3 cells into a new sheet with three columns. I can get the content to end up in example cells E5 F5 and G5.
My problem is when the content gets entered again I need it to be entered into the next free row E6, F6 and G6.
I am currently overwriting the content in E5, F5 and G5 and getting the message “You are pasting data into cells that already contain data. Do you really want to overwrite the existing data?”
What’s the code to move the paste into cells down one row?
Below is what I currently have.
sub Bonus
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 = "$AM$25"
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 = 10
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 = "$E$5"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args4())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
rem ----------------------------------------------------------------------
dim args6(0) as new com.sun.star.beans.PropertyValue
args6(0).Name = "Nr"
args6(0).Value = 3
dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args6())
rem ----------------------------------------------------------------------
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "ToPoint"
args7(0).Value = "$AM$26"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args7())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
rem ----------------------------------------------------------------------
dim args9(0) as new com.sun.star.beans.PropertyValue
args9(0).Name = "Nr"
args9(0).Value = 10
dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args9())
rem ----------------------------------------------------------------------
dim args10(0) as new com.sun.star.beans.PropertyValue
args10(0).Name = "ToPoint"
args10(0).Value = "$F$5"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args10())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
rem ----------------------------------------------------------------------
dim args12(0) as new com.sun.star.beans.PropertyValue
args12(0).Name = "Nr"
args12(0).Value = 3
dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args12())
rem ----------------------------------------------------------------------
dim args13(0) as new com.sun.star.beans.PropertyValue
args13(0).Name = "ToPoint"
args13(0).Value = "$AM$27"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args13())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
rem ----------------------------------------------------------------------
dim args15(0) as new com.sun.star.beans.PropertyValue
args15(0).Name = "Nr"
args15(0).Value = 10
dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args15())
rem ----------------------------------------------------------------------
dim args16(0) as new com.sun.star.beans.PropertyValue
args16(0).Name = "ToPoint"
args16(0).Value = "$G$5"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args16())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
end sub