OpenOffice.org Help TNT
Tips'n'Tricks that somehow didn't make it to the help (yet).
All | Calc | Concepts | Cool Features | General | Help Development | Impress | Macros | Writer

20060522 Monday May 22, 2006
Quick Page Break Toggle

Since we're talking macros:

When going through a document to do the final layout  I occasionally need to adjust page breaks manually. Writer allows page breaks to be a property of a paragraph but the property is buried deep down in a dialog: Format - Paragraph - Text Flow - Breaks.

With this macro toggling a page break for the current paragraph is at the tip of your finger (after you assigned the macro to a shortcut key using Tools - Customize):

sub TogglePagebreak
Dim oVCur As Object
    On Error Goto ERRORHANDLER
   
    oSel = thiscomponent.getcurrentcontroller.getselection

    oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
    ShowProp(oCur.TextTable)
      if oCur.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE then
        oCur.BreakType = com.sun.star.style.BreakType.NONE
    else
        oCur.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE
    end if

    Exit Sub
   
    ERRORHANDLER:
        msgbox ("Cannot change page break settings here:"+chr(13)+chr(13)+Error$,48,"D'oh!")
end sub

This macro switched a page break before on or off. Other BreakTypes are listed in the API Reference.

Character Swapping for Fast Typers

Are you a fast typer?

Then you probably frequently run across the problem that your left index was quicker than expected and you end up with characters in the wrong sequence. I very otfen do ;-)

Andrew Brown sent in a neat little macro that swaps letters to bring them in the correct sequence again :

Sub transpose
' acb, 2001-2003
' very heavily commented trivial macro
' which demonstrates how to get at the text under the cursor
' and do something useful with it.
Dim oDocument as Object
Dim oText as Object
Dim oVCursor, oCursor As Object
Dim sWombat as string
    'shortcut to the active document
    oDocument=thiscomponent
    ' after this, an obscure call gets the current cursor position
    oVCursor = oDocument.currentcontroller.getViewCursor()
    ' but most cursor methods don't work with a view cursor
    ' so now I create an invisible cursor under it, to do the work.
    oText = oVCursor.getText()
    ' the Pitonyak hack
    oCursor=oText.createTextCursorByRange(oVCursor.getStart())
    ' grab the next character
    oCursor.goRight(1,TRUE)
    ' and save a copy of it (no clipboard)
    sWombat = ocursor.getString()
    ' delete the original (seems to be no obvious delete method)
    oCursor.setString("")
    ' next two lines move the invisible cursor
    ' back one letter before where it started
    oCursor.CollapseToStart()
    oCursor.goLeft(1,true)
    ' and now insert the previously cut character
    oText.insertString(oCursor.getStart(),sWombat,false)
    oVCursor.GoLeft(1,false) ' finally return the visible cursor whence it came
End Sub

Now assign that macro to a shortcut key using Tools - Customize.

Happy Sawpping!


Archives
« May 2008
SunMonTueWedThuFriSat
    
1
2
3
4
5
6
7
8
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
       
Today

XML


Send us an email

Links
Referrers