Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Macro for keeping paragraphs together

I used to use a macro from myself in MSOffice to easily keep paragraphs together. Th emacro was

Sub Paralie()

Dim p As Paragraph, bAlready As Boolean

bAlready = True
For Each p In Selection.Paragraphs
    If Not p.KeepTogether Then
        bAlready = False
        Exit For
    End If
Next

If bAlready Then
    'ParaLignesSolidaires 0
    'ParaSolidaires 0
    For Each p In Selection.Paragraphs
        p.KeepWithNext = False
        p.KeepTogether = False
    Next
Else
    'ParaLignesSolidaires 1
    'ParaSolidaires 1
    For Each p In Selection.Paragraphs
        p.KeepWithNext = True
        p.KeepTogether = True
    Next
End If

End Sub

I search for the same in Libre Office and did not find. So, here is my version for anybody needing it

Sub LinkedPara
    dim oDoc as object
    dim oCursor as object
    dim oSelections as object
    dim oSel as object
    dim oPE as object
    dim oPar as object
    dim bAlready as boolean

    ' for reference
    ' MsgBox  vObj.dbg_methods              'Methods for this object.
    ' MsgBox  vObj.dbg_supportedInterfaces  'Interfaces for by this object.
    ' MsgBox  vObj.dbg_properties           'Properties for this object.

    oDoc = ThisComponent
    oSelections = oDoc.getCurrentSelection() 
    oSel = oSelections.getByIndex(0)    

    oPE = oSel.createEnumeration()
    bAlready = True
    Do While oPE.hasMoreElements()
        oPar = oPE.nextElement()
        ' msgbox oPar.dbg_properties
        if not oPar.ParaKeepTogether then
            bAlready = False
            Exit do
        end if
    Loop
    'MsgBox "bAlready=" & bAlready, 64

    'msgBox oPE.dbg_methods
    oPE = oSel.createEnumeration()
    Do While oPE.hasMoreElements()
        oPar = oPE.nextElement()
        oPar.ParaKeepTogether = not bAlready
        oPar.ParaKeepTogether = not bAlready
    Loop

End Sub

Feel free to correct me or enhance as this is my first macro for Libre Office.

The idea is to link the macro to a keyboard shortcut to easily switch a pack of paragraphs from being kept together or not. I do this very often to get a nice page formatting. E.g.

Title level1
some text
Title level2

It is frustrating to get the "Title level2" at the top of a page. Making the "some text" linked allows to avoid that.

Macro for keeping paragraphs together

I used to use a macro from myself in MSOffice to easily keep paragraphs together. Th emacro was

Sub Paralie()

Dim p As Paragraph, bAlready As Boolean

bAlready = True
For Each p In Selection.Paragraphs
    If Not p.KeepTogether Then
        bAlready = False
        Exit For
    End If
Next

If bAlready Then
    'ParaLignesSolidaires 0
    'ParaSolidaires 0
    For Each p In Selection.Paragraphs
        p.KeepWithNext = False
        p.KeepTogether = False
    Next
Else
    'ParaLignesSolidaires 1
    'ParaSolidaires 1
    For Each p In Selection.Paragraphs
        p.KeepWithNext = True
        p.KeepTogether = True
    Next
End If

End Sub

I search for the same in Libre Office and did not find. So, here is my version for anybody needing it

Sub LinkedPara
    dim oDoc as object
    dim oCursor as object
    dim oSelections as object
    dim oSel as object
    dim oPE as object
    dim oPar as object
    dim bAlready as boolean

    ' for reference
    ' MsgBox  vObj.dbg_methods              'Methods for this object.
    ' MsgBox  vObj.dbg_supportedInterfaces  'Interfaces for by this object.
    ' MsgBox  vObj.dbg_properties           'Properties for this object.

    oDoc = ThisComponent
    oSelections = oDoc.getCurrentSelection() 
    oSel = oSelections.getByIndex(0)    

    oPE = oSel.createEnumeration()
    bAlready = True
    Do While oPE.hasMoreElements()
        oPar = oPE.nextElement()
        ' msgbox oPar.dbg_properties
        if not oPar.ParaKeepTogether then
            bAlready = False
            Exit do
        end if
    Loop
    'MsgBox "bAlready=" & bAlready, 64

    'msgBox oPE.dbg_methods
    oPE = oSel.createEnumeration()
    Do While oPE.hasMoreElements()
        oPar = oPE.nextElement()
        oPar.ParaKeepTogether = not bAlready
        oPar.ParaKeepTogether = not bAlready
    Loop

End Sub

Feel free to correct me or enhance as this is my first macro for Libre Office.

The idea is to link the macro to a keyboard shortcut to easily switch a pack of paragraphs from being kept together or not. I do this very often to get a nice page formatting. E.g.

Title level1
some text
Title level2

It is frustrating to get the "Title level2" at the top of a page. Making the "some text" linked allows to avoid that.

Macro for keeping paragraphs together

I used to use a macro from myself in MSOffice to easily keep paragraphs together. Th emacro was

Sub Paralie()

Dim p As Paragraph, bAlready As Boolean

bAlready = True
For Each p In Selection.Paragraphs
    If Not p.KeepTogether Then
        bAlready = False
        Exit For
    End If
Next

If bAlready Then
    'ParaLignesSolidaires 0
    'ParaSolidaires 0
    For Each p In Selection.Paragraphs
        p.KeepWithNext = False
        p.KeepTogether = False
    Next
Else
    'ParaLignesSolidaires 1
    'ParaSolidaires 1
    For Each p In Selection.Paragraphs
        p.KeepWithNext = True
        p.KeepTogether = True
    Next
End If

End Sub

I search searched for the same in Libre Office and did not find.

The idea is to link the macro to a keyboard shortcut to easily switch a pack of paragraphs from being kept together or not. I do this very often to get a nice page formatting. E.g.

Title level1
some text
Title level2

It is frustrating to get the "Title level2" at the top of a page. Making the "some text" linked allows to avoid that.

Macro for keeping paragraphs together

I used to use a macro from myself in MSOffice to easily keep paragraphs together. Th emacro The macro was

Sub Paralie()

Dim p As Paragraph, bAlready As Boolean

bAlready = True
For Each p In Selection.Paragraphs
    If Not p.KeepTogether Then
        bAlready = False
        Exit For
    End If
Next

If bAlready Then
    'ParaLignesSolidaires 0
    'ParaSolidaires 0
    For Each p In Selection.Paragraphs
        p.KeepWithNext = False
        p.KeepTogether = False
    Next
Else
    'ParaLignesSolidaires 1
    'ParaSolidaires 1
    For Each p In Selection.Paragraphs
        p.KeepWithNext = True
        p.KeepTogether = True
    Next
End If

End Sub

I searched for the same in Libre Office and did not find.

The idea is to link the macro to a keyboard shortcut to easily switch a pack of paragraphs from being kept together or not. I do this very often to get a nice page formatting. E.g.

Title level1
some text
Title level2

It is frustrating to get the "Title level2" at the top of a page. Making the "some text" linked allows to avoid that.