--- Comment #18 from Paul <> ---
Ok, I asked and received a really nice macro reply. I slightly altered it by
adding an Input box to spec the number of columns on the fly, and to exit if
the input box was left blank. The Ask thread is at

I will print the finished macro below. But there is one strange problem. Though
the macro works fine when invoked from the Basic editor, it errors out when I
use a custom Menu entry for it. The error is: 

    A Scripting Framework error occurred while running the Basic script 

    Message: wrong number of parameters!

Also errors out via hotkey. Here's the macro. I would like to see something
like this incorporated into Core somehow. :)

Sub Writer_SelectionToColumns( ByRef iNumColumns As Integer, Optional
sSeparator )
  REM Courtesy of librebel, 2/19/18; My input box added
  REM Convert selected Text into a specified number of Table Columns.
  REM <iNumColumns> : The number of columns for the Table to be created.
  REM <sSeparator>  : String pattern separating the Text portions to be
inserted into the Table Cells.
  REM NB. This method does not preserve the existing text format of the
  REM TODO: Format text; AutoFormat Table.
    Dim oDocument As Object : oDocument = ThisComponent
    If oDocument.supportsService( "" ) Then
        Dim iNumColumns As Integer 
        iNumColumns =  InputBox("Enter desired number of columns (blank = 0)")

        If iNumColumns <= 0 Then Exit Sub
        If IsMissing( sSeparator ) Or sSeparator  = "" Then sSeparator =

        Dim oSelection As Object : oSelection =
oDocument.CurrentController.Selection.getByIndex( 0 )
        Dim aParts() As String   : aParts     = Split( oSelection.getString(),
sSeparator )
        Dim iNumRows As Integer  : iNumRows   = ( 1 + uBound( aParts ) ) \
        If ( 1 + uBound( aParts ) ) Mod iNumColumns > 0 Then iNumRows =
iNumRows + 1    REM Ceiling()...
        If iNumRows = 0 Then Exit Sub

        Dim oTable As Object     : oTable     = oDocument.createInstance(
"" )
        oTable.initialize( iNumRows, iNumColumns )

        oDocument.Text.insertTextContent( oSelection, oTable, True )    REM
Replace selection with Table.

        Dim i As Integer
        For i = 0 To uBound( aParts )
            oTable.getCellByPosition( i Mod iNumColumns, i \ iNumColumns
).setString( aParts( i ) )
        Next i

    End If

End Sub

You are receiving this mail because:
You are the assignee for the bug.
Libreoffice-bugs mailing list

Reply via email to