# help to write a macro for calc [closed]

I have very often in Calc sheets many cells looking like

I need to add a line break before the "[" and use a bold format for all between and including "[". "]" so that the cell looks like:

Using the record macro function does not work in this case (which I can understand) and I don't have enough macro programming knowledge to write a macro myself from the scratch.

Any help to write this macro is highly appreciated.

LibO version: 4.0.5.2 XP/SP3

edit retag reopen merge delete

### Closed for the following reason question is not relevant or outdated by Alex Kemp close date 2015-11-10 04:59:40.449053

Sort by » oldest newest most voted

This macro finds the opening bracket in text for a selection of cells, inserts a line feed and emboldens the balance of the line. I had to resize the cell vertically to see both resulting lines.

Sub BoldPart
rem <a href="http://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=47512">http://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=47512</a>
rem and <a href="http://www.oooforum.org/forum/viewtopic.phtml?t=181971">http://www.oooforum.org/forum/viewtopic.phtml?t=181971</a>
Dim oDoc As Object
Dim oSelection As Object
Dim oCell As Object
Dim oCursor As Object
Dim oText As Object
Dim colonLoc As Long
Dim i As Long

oDoc = ThisComponent
oSelection = oDoc.CurrentController.Selection

for i = 0 to oSelection.Rows.Count - 1
oCell = oSelection.getCellByPosition(0,i)
oString=oCell.getString()
oText = oCell.getText()
bracketLoc = InStr(oText.String,"[")
if bracketLoc > 0 then
oCursor = oText.createTextCursor
oCursor.String=oString
oCursor.gotoStart(False)
oCursor.goRight(bracketLoc-1,False)
oCursor.string=chr(10)
oCursor.gotoend(True)
oCursor.CharWeight = com.sun.star.awt.FontWeight.BOLD
endif
next i
End Sub

more