Hi, I want a macro that merges manually selected cells, then applies a style, then writes text in the merged block, and then centers the text. I found a way to perform all the individual tasks, but the complete macro fails (without errors) after merging and applying the style. I think this is because after merging the cells, I have no longer a valid reference to the merged cells. If I manually select the merged cells and then run the macro a second time, then the rest of the macro executes as expected and the text is written to the merged block.
So the question is how I can reference the newly merged block from within the macro.
sub applyStyle(strStyle, strText, blnCentered) theSelection=ThisComponent.CurrentSelection //'split the selection just in case it already contains merged cells theSelection.merge(False) //'merge the cells theSelection.merge(True) //' apply the style dim document as object dim dispatcher as object document = ThisComponent.CurrentController.Frame dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") dim args1(1) as new com.sun.star.beans.PropertyValue args1(0).Name = "Template" args1(0).Value = strStyle args1(1).Name = "Family" args1(1).Value = 2 dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args1()) //'enter the text <== fails in the first run theSelection.setString(strText) // 'center the text if blnCentered = true then theSelection.HoriJustify=com.sun.star.table.CellHoriJustify.CENTER theSelection.VertJustify=com.sun.star.table.CellVertJustify.CENTER endif end sub