Ask Your Question

Run full document Macro

asked 2017-06-24 23:58:11 +0200

lilcobra gravatar image

Hello, everyone! I need to run a macro to the full document.

The macro its very simple.

1) set the cursor at the begining of the page 2) press shift, then press the END key, this selects the full line text. 3) change the color of the selected tex 4) set the text size to 24

5) press the HOME key, this sends the cursor to the begining of the text line 6) press the DOWN ARROW ket twice, this skips one line of text

The avobe steps are the whole micro. Now I need to know how to run it the full document.

Note: I try to edit the micro,I just copy the steps and paste them below the original code and it WORKS very well.

But to edit all the steps takes alot of work.

I hope that there is a way to get the micro into a ' for loop ' or something.

Thanks in advance for the help.

If there any source to learn to crate scripts for LibreOffice please let me know. Thanks again. lilcobra

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2017-06-25 01:02:57 +0200

librebel gravatar image

updated 2017-06-25 23:33:46 +0200

Hello @lilcobra, if i understood your question correctly, then the following macro would format your entire document based on your specifications above:

Sub FormatPage_lilcobra()
    Dim oTextCursor as Object, oText As Object, b As Boolean
    oText = ThisComponent.getText()
    oTextCursor = oText.createTextCursor()
    oTextCursor.gotoStart( False )
        b = oTextCursor.gotoEndOfParagraph( True )
        oTextCursor.CharHeight = 24
        oTextCursor.CharColor = 16222213    REM change text color.
        b = oTextCursor.gotoNextParagraph( False )  REM skip 1 line.
        b = oTextCursor.gotoNextParagraph( False )
    Loop While b
End Sub

EDIT: per line

Sub FormatPage_lilcobra2()
REM Per line ( not per paragraph ).
    Dim oViewCursor as Object, b As Boolean
    oViewCursor = ThisComponent.getCurrentController.getViewCursor()
    oViewCursor.gotoStart( False )
        b = oViewCursor.goDown( 1, True )
        oViewCursor.CharHeight = 24
        oViewCursor.CharColor = 16222213    REM change text color.
        b = oViewCursor.goDown( 1, False )
    Loop While b
End Sub
edit flag offensive delete link more

answered 2017-06-25 02:39:38 +0200

lilcobra gravatar image

updated 2017-06-25 02:45:06 +0200

Thank you, Librebel.

I will give it a try and let you know.

thank you for the help.

But the way this is the code that was created by recording the macro... then I was just copy and editing the args02 numbers and then paste at the end.... over and over again... it works... but looks like a silly code.

code rem ---------------------------------------------------------------------- dispatcher.executeDispatch(document, ".uno:EndOfLineSel", "", 0, Array())

rem ---------------------------------------------------------------------- dim args68(0) as new args68(0).Name = "FontColor" args68(0).Value = 16222213

dispatcher.executeDispatch(document, ".uno:FontColor", "", 0, args68())

rem ---------------------------------------------------------------------- dim args69(2) as new args69(0).Name = "FontHeight.Height" args69(0).Value = 24 args69(1).Name = "FontHeight.Prop" args69(1).Value = 100 args69(2).Name = "FontHeight.Diff" args69(2).Value = 0

dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args69())

rem ---------------------------------------------------------------------- dispatcher.executeDispatch(document, ".uno:GoToStartOfLine", "", 0, Array())

rem ---------------------------------------------------------------------- dim args70(1) as new args70(0).Name = "Count" args70(0).Value = 1 args70(1).Name = "Select" args70(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args70())

rem ---------------------------------------------------------------------- dim args71(1) as new args71(0).Name = "Count" args71(0).Value = 1 args71(1).Name = "Select" args71(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args71())

edit flag offensive delete link more


You're welcome @lilcobra, i edited the example to adjust the textcolor to 16222213.

librebel gravatar imagelibrebel ( 2017-06-25 02:47:53 +0200 )edit

Hello librebel, i try the macro it runs Ok and changes the text color and the text hight, BUt it Not skips the text line. I try to edit the macro to make it skip one line but dint work. I hope you have the answer. thank you.

lilcobra gravatar imagelilcobra ( 2017-06-25 19:53:22 +0200 )edit

I posted a second example in my answer, please see if that works.

librebel gravatar imagelibrebel ( 2017-06-25 23:34:53 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-06-24 23:58:11 +0200

Seen: 83 times

Last updated: Jun 25 '17