First macros for page formating

Creating a macro - Writing a Script - Using the API

First macros for page formating

Postby Lautrec » Sat Nov 18, 2017 1:49 am

Hi,

I trying to create macros (in LibreOffice) that when I'm open a document (single page document for example)
macros automatically formatting page size and margins, font family and size.
I use button "Record Macros" but when I use this macros the following is happen.

Macros open dialog window "page style: firs page" and if I want to go on I must enter margin values by hand.
After that macros do the next steps of the recording otherwise nothing is happen.


Never before I'm used macros.
LibreOffice 5.4 on Windows 10
Lautrec
 
Posts: 4
Joined: Sat Nov 18, 2017 1:06 am

Re: First macros for page formating

Postby Zizi64 » Sat Nov 18, 2017 11:09 am

Use a preformatted Template instead of the macros to achieve this task.
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6061
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: First macros for page formating

Postby RoryOF » Sat Nov 18, 2017 11:13 am

I agree with Zizi64; all this information can be inserted into OpenOffice templates and it is a simple matter to start Writer documents with a custom template or choose one of a number of such templates. See
[Tutorial] Creating a new default template
Apache OpenOffice 4.1.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25492
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: First macros for page formating

Postby Zizi64 » Sat Nov 18, 2017 11:34 am

I use button "Record Macros" but when I use this macros the following is happen.

Macros open dialog window "page style: firs page" and if I want to go on I must enter margin values by hand.
After that macros do the next steps of the recording otherwise nothing is happen.

The macro recorder can not record all of the user's activity. You must WRITE your macros based on the API functions and procedures. API: Application Programming Interface. Start it with studying the Andrew Pitonyak's free macro books.
Last edited by Zizi64 on Sat Nov 18, 2017 6:55 pm, edited 1 time in total.
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6061
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: First macros for page formating

Postby RoryOF » Sat Nov 18, 2017 11:51 am

You might get away with reading the manual for OpenOffice BASIC at
https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide

Be advised that macro programming in OpenOffice is not as simple as in some other office suites; OpenOffice is so powerful that frequently one can use its inbuilt facilities to achieve a desired end without any need for macro programming.
Apache OpenOffice 4.1.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25492
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: First macros for page formating

Postby Lautrec » Sat Nov 18, 2017 3:28 pm

The most important thing that I want to do is not just to change page format (A5, A3 etc.) but margins too without writing new numbers for Left, Right, Top, Bottom.
This is the reason because of I trying to use macros. I found a little info but I don't know how to create macros to do this. Only this, because the procedure from the first post looks like too complicate.
So, in this case I could create two different macros:
a) one for page format include new margin and
b) another for paragraphs, text style, size.
The second one is easy, but how can I do the firs one?

_________
I am home user, not a pro neither a programmer. I have a lot of personal documents and I trying to edit most of them. I install LibreOffice before a week ago. I used FreeOffice 2016 before which was great for my simple tasks until now.
LibreOffice 5.4 on Windows 10
Lautrec
 
Posts: 4
Joined: Sat Nov 18, 2017 1:06 am

Re: First macros for page formating

Postby Villeroy » Sat Nov 18, 2017 3:46 pm

Create 2 templates and use either one depending on your needs.
Or switch between 2 page in one template.
Creating styles by means of macros is pointless.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24652
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: First macros for page formating

Postby RoryOF » Sat Nov 18, 2017 4:42 pm

Look at this thread:
https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=82036

I think there is a macro in that thread to set page margins, but honestly you would be better to use customised templates.
Apache OpenOffice 4.1.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25492
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: First macros for page formating

Postby Lautrec » Sat Nov 18, 2017 5:25 pm

OK. Let's forget macros for a moment.
I'm sorry but I don't understand you about a template.
When I create template and save as default it can be use for create a new document, isn't it?
But when I open existed document which was formatted before that, how can I use my template in this case to format existed document?
Do I miss something or this is impossible?

Ctr+O—>choose file—>open, so how to use template?

_____
By the way thanks for the link to the book.
LibreOffice 5.4 on Windows 10
Lautrec
 
Posts: 4
Joined: Sat Nov 18, 2017 1:06 am

Re: First macros for page formating

Postby RoryOF » Sat Nov 18, 2017 6:15 pm

Apache OpenOffice 4.1.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25492
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: First macros for page formating

Postby Zizi64 » Sat Nov 18, 2017 10:36 pm

Backt to the API and the macros...

I trying to create macros (in LibreOffice) that when I'm open a document (single page document for example)
macros automatically formatting page size and margins, font family and size.


Are you using only one Paragraph Style (for example the Default paragraph style) in your documents???

Always work with Styles instead of the direct formatting properties. It is much easier to automatize the adjusting procedure of the properties in the applied styles - than to get the manually formatted parts of a document, and to get and change theirs manually adjusted properties.
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6061
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: First macros for page formating

Postby RoryOF » Sat Nov 18, 2017 10:50 pm

If the intention is to change the formatting of an existing work or a small number of works, I suggest macros are not the way to go. Informed use of Find and Replace, rationalisation of the number of styles used and adjustment of their settings may be the way to go. I have downloaded a copy of War and Peace (550,000 words), removed the paragraph marks, set styles and formatted the entire book into normal book format in less than 15 minutes.
Apache OpenOffice 4.1.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25492
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: First macros for page formating

Postby Lautrec » Sun Nov 19, 2017 12:42 am

RoryOF wrote:If the intention is to change the formatting of an existing work or a small number of works, ....................
...... I have downloaded a copy of War and Peace (550,000 words), ...... the entire book into normal book format in less than 15 minutes..

Well it's not same like my small project but this is exactly that I want + new page dimensions and margins.
The second is a joke, right? I mean it's hard to believe, but well done.

RoryOF wrote:Look at this thread:
https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=82036

I think there is a macro in that thread to set page margins, but honestly you would be better to use customised templates.


Thanks RoryOF. Finely I found partial solution.
I don't understand almost nothing but the macros do what I want. I edited only margins value and after that macros changed the page size and margins just like I want.
In my case: A5; L,R,T,B = 0,8 cm.
I don't know how to edit this macros to change formats of paragraphs and characters so perhaps I'll trying the second macros.

Code: Select all   Expand viewCollapse view
sub changeallpagesizesusedindocument
rem Portrait Sizes:
newpagesizeWidth = 14800      'this is my value
newpagesizeHeight = 21000     'this is my value
newTopMargin = 800            'this is my value
newBottomMargin = 800         'this is my value
newLeftMargin = 800           'this is my value
newRightMargin = 800          'this is my value


oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.jumptofirstpage(false)

do
s = oViewCursor.PageStyleName
oStyle = ThisComponent.StyleFamilies.getByName("PageStyles").getByName(s)
if oStyle.IsLandscape=True then   'this is for Landscape, the margins as if we rotated portrait 90°right, change as you like
oStyle.Width = newpagesizeHeight
oStyle.Height = newpagesizeWidth
oStyle.TopMargin = newLeftMargin
oStyle.BottomMargin = newRightMargin
oStyle.LeftMargin = newBottomMargin
oStyle.RightMargin = newTopMargin
else    'this is for portrait
oStyle.Width = newpagesizeWidth
oStyle.Height = newpagesizeHeight
oStyle.TopMargin = newTopMargin
oStyle.BottomMargin = newBottomMargin
oStyle.LeftMargin = newLeftMargin
oStyle.RightMargin = newRightMargin
end if

loop while oViewCursor.jumptonextpage(false)
oViewCursor.jumptofirstpage(false)

End Sub


One additional question. How do I create macros button on toolbar or into menu button for faster work?
LibreOffice 5.4 on Windows 10
Lautrec
 
Posts: 4
Joined: Sat Nov 18, 2017 1:06 am

Re: First macros for page formating

Postby RoryOF » Sun Nov 19, 2017 8:54 am

Lautrec wrote:
RoryOF wrote:If the intention is to change the formatting of an existing work or a small number of works, ....................
...... I have downloaded a copy of War and Peace (550,000 words), ...... the entire book into normal book format in less than 15 minutes..

Well it's not same like my small project but this is exactly that I want + new page dimensions and margins.
The second is a joke, right? I mean it's hard to believe, but well done.


No, not a joke: in brief - I don't note all I do, but the major steps are - Modify Default page style to be A5, three passes of Find and Replace to remove extraneous paragraph marks and turn text into paragraphs, Select all text and apply Default Paragraph style; Find all chapter headings and format them with Heading I, Insert a ToC, set Headers on Default page styles. Autotext to change quotes to curly quotes

Easy-peasy - I often do this to books I wish to print and bind.
Apache OpenOffice 4.1.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25492
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: First macros for page formating

Postby Zizi64 » Sun Nov 19, 2017 9:41 am

The second is a joke, right? I mean it's hard to believe, but well done.

It is not a joke.
But you can not achieve this in a badly structured document. If the document contains lots of manual formatting properties: then you can delete them by a CTRL-A; Ctrl-M command pair...
But when the indents of the paragraphs was created by TABs (or by spaces!!!) and there are lots of other terrible "electric typewriter"-like formattings) then you must work more than 15 minutes...
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6061
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: First macros for page formating

Postby RoryOF » Sun Nov 19, 2017 10:41 am

In fact, Zixi64, most "typewriter" like spacings can be removed by careful use of Find and Replace.
Apache OpenOffice 4.1.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25492
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: First macros for page formating

Postby Zizi64 » Sun Nov 19, 2017 11:19 am

In fact, Zixi64, most "typewriter" like spacings can be removed by careful use of Find and Replace.


Yes, it is true.

But when the document contains only one paragraph style, and lots of the different size indents for the paragraphs, then you will/must play with it more than 15 minutes. (I had see such documents - unfortunately. :crazy: )
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6061
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 11 guests