We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

How do I draw a bottom border line using macro in the header?

asked 2019-02-19 16:22:57 +0200

Craig22 gravatar image


I have the intention to me a GUI programming, with which I am comfortable several new page templates can create.

If a page template with the same name exists, it will be deleted from the program. Then a new page template with the same name, created on the basis of the specified properties.

This can be done only partially. My problem is that I am not in the header, nor in the footer can draw a border line.

Using MRI are the correct struct properties are displayed:

REM Borderline Struct
REM Header = BottomBorder
REM Footer = TopBorder
Dim aLine as New com.sun.star.table.BorderLine
    aLine.OuterLineWidth = 35
    aLine.LineDistance = 10
mri aLine

Now I tried in a simple way that struct the page template to assign:


This does not work.

Here is the entire code:

REM  *****  BASIC  *****

REM ╔═══════════════════════════════════════════════════════════════════════╗
REM ║                                                                       ║
REM ║   This macro creates a new page style with the defined properties.    ║
REM ║   If a page style with the same name exists,                          ║
REM ║   then the old style will be deleted                                  ║
REM ║                                                                       ║
REM ╚═══════════════════════════════════════════════════════════════════════╝

Dim oPageStyle as Object

Sub NewLeftPageStyle()
Dim oDoc As Object
'Dim oPageStyle as Object

Dim nCnt as Integer
Dim sStyle as String


REM Example:
REM sStyle= "My_Pagestyle Left Page"
sStyle= InputBox ("Please insert the new PageStyle Name: ","New PageStyle")

REM PageStyle-Objekt
oPageStyle = oDoc.createInstance( "com.sun.star.style.PageStyle" )

'mri oDoc.StyleFamilies.getByName("PageStyles")

REM PageStyle Counter for all existing Pagestyles

    for i = 0 to nCnt-1
        ' If new PageStyle-Name = old PageStyle-Name, then delete old Pagestyle
        If sStyle=odoc.StyleFamilies.getByName("PageStyles").getByIndex(i).Name then
            ' delete
                exit for
        End if
    next i

REM Borderline Struct
REM Header = BottomBorder
REM Footer = TopBorder
Dim aLine as New com.sun.star.table.BorderLine
    aLine.OuterLineWidth = 35
    aLine.LineDistance = 10

' mri aLine 
' mri oPageSTyle

    REM New PageStyle-Properties
    With oPageStyle
        ' Name
'       .BorderDistance
'       .BottomBorder=aLine
'       .BottomBorderDistance
'       .FooterBottomBorder=aLine
REM --> don't works 
REM there is no line in Header visible

    End With

    ' Create new PageStyle with the Properties above
    oDoc.StyleFamilies.getByName( "PageStyles" ).insertByName(sStyle,oPageStyle )
End Sub

Which Code statement is correct to draw a thin line under the header.



edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2019-03-25 21:41:43 +0200

Craig22 gravatar image

Hello Gord,

Thank you very much for your feedback.

However, your macro does not put a line under a header, but draws a line below a paragraph in the body text.

In the meantime, I have found a solution. It was my fault.

In the code I gave the instruction to delete an existing page style. Thereafter, logically, a new page style must be generated again. This I have missed and that's why the header statements were ignored.

Here is my Testdocument and a description...

Best Regards


edit flag offensive delete link more

answered 2019-03-25 19:17:25 +0200

G o r d gravatar image

I too struggled with this until I finally and got it to work. Here is the key point:

  • Sometimes the 'Record Macro' doesn't work for clicking on toolbar shortcuts and you have to record going through the menus.

Example: What follows is an example to get a thick bottom border

sub BottomLineHeavy

rem ---- This macro was recorded using:
rem -- "Format (Alt+'0'), Cells (Alt+'l'+'Enter'), User-defined (Alt+'u' then use cursor keys
rem -- to navigate and spacebar to select sides - also note that the left side may be
rem -- selected by default - pressing the spacebar three times cycles through your
rem -- choices), Tab to Style (cursor up and down to select) then tab to Width to set
rem -- line thickness."

rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------

dim args1(7) as new com.sun.star.beans.PropertyValue
args1(0).Name = "BorderOuter.LeftBorder"
args1(0).Value = Array(0,0,0,0,0,0)
args1(1).Name = "BorderOuter.LeftDistance"
args1(1).Value = 0
args1(2).Name = "BorderOuter.RightBorder"
args1(2).Value = Array(0,0,0,0,0,0)
args1(3).Name = "BorderOuter.RightDistance"
args1(3).Value = 0
args1(4).Name = "BorderOuter.TopBorder"
args1(4).Value = Array(0,0,0,0,0,0)
args1(5).Name = "BorderOuter.TopDistance"
args1(5).Value = 0
args1(6).Name = "BorderOuter.BottomBorder"
args1(6).Value = Array(0,0,44,0,0,44)
args1(7).Name = "BorderOuter.BottomDistance"
args1(7).Value = 0

dispatcher.executeDispatch(document, ".uno:BorderOuter", "", 0, args1())

end sub
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-02-19 16:22:57 +0200

Seen: 571 times

Last updated: Mar 25 '19