Ask Your Question
0

help to write a macro for calc [closed]

asked 2013-09-26 10:31:07 +0200

ROSt52 gravatar image

updated 2015-11-10 04:59:31 +0200

Alex Kemp gravatar image

I have very often in Calc sheets many cells looking like

image description

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:

image description

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 flag offensive 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

1 Answer

Sort by » oldest newest most voted
4

answered 2013-09-26 19:34:54 +0200

w_whalley gravatar image

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
edit flag offensive delete link more

Comments

@w_whalley Thank your very much for this macro. I got it running and it works just fine!

ROSt52 gravatar imageROSt52 ( 2013-09-27 06:37:40 +0200 )edit

Question Tools

1 follower

Stats

Asked: 2013-09-26 10:31:07 +0200

Seen: 2,646 times

Last updated: Sep 27 '13