Macro merging

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Diaman
Posts: 1
Joined: Fri Mar 10, 2017 7:01 pm

Macro merging

Post by Diaman »

I have a list of 1087 names and I need help with a macro to merge cells from 4 columns - A, B, C and D (Output, First name, Middle name and Last name)
I want the full name in cellA (Output) from row 1 to 1087.

A formula is easy but I cant use them for this, and its too much data to do individually.
I have some code below by recording a macro - It shows selecting and merging cells A2 to D2 (and using this i still need to confirm the merge by clicking Yes)

What I hope you can do is give me a loop function that will go through each row and merge the corresponding A to D cells


sub threebecomeone
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 = "$A$2:$D$2"

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

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "MoveContents"
args2(0).Value = true

dispatcher.executeDispatch(document, ".uno:ToggleMergeCells", "", 0, args2())
OpenOffice 4.1 on Windows
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro merging

Post by RoryOF »

Insert new column A, insert a concatenation formula in A1, select that cell, then pull the formula down with the black square on the bottom right of the selected cell.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Post Reply