Page 1 of 1

First macros for page formating

PostPosted: Sat Nov 18, 2017 1:49 am
by Lautrec
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.

Re: First macros for page formating

PostPosted: Sat Nov 18, 2017 11:09 am
by Zizi64
Use a preformatted Template instead of the macros to achieve this task.

Re: First macros for page formating

PostPosted: Sat Nov 18, 2017 11:13 am
by RoryOF
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

Re: First macros for page formating

PostPosted: Sat Nov 18, 2017 11:34 am
by Zizi64
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.

Re: First macros for page formating

PostPosted: Sat Nov 18, 2017 11:51 am
by RoryOF
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.

Re: First macros for page formating

PostPosted: Sat Nov 18, 2017 3:28 pm
by Lautrec
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.

Re: First macros for page formating

PostPosted: Sat Nov 18, 2017 3:46 pm
by Villeroy
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.

Re: First macros for page formating

PostPosted: Sat Nov 18, 2017 4:42 pm
by RoryOF
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.

Re: First macros for page formating

PostPosted: Sat Nov 18, 2017 5:25 pm
by Lautrec
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.

Re: First macros for page formating

PostPosted: Sat Nov 18, 2017 6:15 pm
by RoryOF

Re: First macros for page formating

PostPosted: Sat Nov 18, 2017 10:36 pm
by Zizi64
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.

Re: First macros for page formating

PostPosted: Sat Nov 18, 2017 10:50 pm
by RoryOF
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.

Re: First macros for page formating

PostPosted: Sun Nov 19, 2017 12:42 am
by Lautrec
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?

Re: First macros for page formating

PostPosted: Sun Nov 19, 2017 8:54 am
by RoryOF
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.

Re: First macros for page formating

PostPosted: Sun Nov 19, 2017 9:41 am
by Zizi64
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...

Re: First macros for page formating

PostPosted: Sun Nov 19, 2017 10:41 am
by RoryOF
In fact, Zixi64, most "typewriter" like spacings can be removed by careful use of Find and Replace.

Re: First macros for page formating

PostPosted: Sun Nov 19, 2017 11:19 am
by Zizi64
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: )