Set Paper Size in AppleScript

J

JanvanDie

Version: 2008
Operating System: Mac OS X 10.5 (Leopard)
Processor: intel

Hello AppleScript specialists,

I try to set the paper size using:

set paper size of page setup of active document to paper a4

No errors from the compiler, but my document remains letter format.

This is also not working:

set page width of page setup of active document to (centimeters to points centimeters 20.99)
set page height of page setup of active document to (centimeters to points centimeters 29.7)

What am I doing wrong?
Thanks for your help!

Jan
 
M

MC

Hello AppleScript specialists,

I try to set the paper size using:

set paper size of page setup of active document to paper a4

No errors from the compiler, but my document remains letter format.

Are you switching between A4 and US Legal, or do you want A4 to be the
default?

If the latter, go to File -> Page Setup -> Select the paper size then Go
to "Page Settings" and click on Default. All future Word documents
should be A4.
 
J

JanvanDie

Are you switching between A4 and US Legal, or do you want A4 to be the default?
If the latter, go to File -> Page Setup -> Select the paper size then Go
to "Page Settings" and click on Default. All future Word documents
should be A4.

Thanks MC, but I'm trying to write a script that converts docs from Legal to A4 and sets the margins in the way I like. (That last part is working!)

Jan
 
J

janvdie

It looks like you¹re just missing a reference to the section.  The following
example AppleScript worked for me:

tell application "Microsoft Word"
    set paper size of page setup of section 1 of active document to paper a4
end tell

Thanks Shawn, but it doesn't work on my computer.
Al least... when I look at the dialog panel of Page Setup in the File
menu, nothing has changed.

Jan
 
J

John McGhie

Hi Jan:

How many sections do you have in that document?

If there is more than one, you have to return each one and set them
individually.

Hope this helps


Thanks Shawn, but it doesn't work on my computer.
Al least... when I look at the dialog panel of Page Setup in the File
menu, nothing has changed.

Jan

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
http://jgmcghie.fastmail.com.au/
Sydney, Australia. S33°53'34.20 E151°14'54.50
+61 4 1209 1410, mailto:[email protected]
 
J

JanvanDie

Hi John,

I am writing a convertor. I don't know how many sections there will be in the document. Perhaps AppleScript can count them, but is this really the way?
I can set the orientation of Page Setup with one instruction.
Why should the paper size involve more?

Best regards,

Jan
 
J

John McGhie

Hi Jan:

Because a document contains as many paper sizes as there are sections. Look
up the Word Document Object Model in the VBA Help in Word 2003/4 for a nice
picture of the structure :)

Paper size is a "Section" property. All "page-level" properties are stored
in the section breaks that terminate each section.

A document has from 1 to 255 sections. Each of those sections can
potentially have a different page layout. And each can potentially have six
different headers and footers.

If you look at the following VBA, it iterates the sections in the document
for precisely this reason.

Sub FixFooters()
Dim aSection As Section
On Error GoTo error

For Each aSection In ActiveDocument.Sections
If aSection.Index > 3 Then
With aSection
If .Headers(wdHeaderFooterPrimary).Exists Then
..Headers(wdHeaderFooterPrimary).LinkToPrevious = True
If .Headers(wdHeaderFooterEvenPages).Exists Then
..Headers(wdHeaderFooterEvenPages).LinkToPrevious = True
If .Footers(wdHeaderFooterPrimary).Exists Then
..Footers(wdHeaderFooterPrimary).LinkToPrevious = True
If .Footers(wdHeaderFooterEvenPages).Exists Then
..Footers(wdHeaderFooterEvenPages).LinkToPrevious = True
End With
End If
Next ' aSection

GoTo AllDone

error:
If Err = 4605 Then Resume Next

AllDone:

End Sub

You must apply ALL the page-level properties you wish to change to EVERY
section in the document.

I suspect that for your purposes, you can delete the Error Handler. If you
are playing with headers and footers, you have to trap the error that blows
you up if the header or footer you want has not yet been instantiated.

Hope this helps

Hi John,

I am writing a convertor. I don't know how many sections there will be in the
document. Perhaps AppleScript can count them, but is this really the way?
I can set the orientation of Page Setup with one instruction.
Why should the paper size involve more?

Best regards,

Jan

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
http://jgmcghie.fastmail.com.au/
Sydney, Australia. S33°53'34.20 E151°14'54.50
+61 4 1209 1410, mailto:[email protected]
 
J

JanvanDie

Thanks John,

You gave me a lot to think about.
I will experiment with this information during the weekend.
I hope I get it running!

Best regards,

Jan
 
J

JanvanDie

Hi John,

You said:
Paper size is a "Section" property. All "page-level" properties are stored in the section breaks that terminate each section.

I tried this:
set Amount to number of sections of active document
set counter to 1
repeat while counter ≤ Amount
set paper size of section counter of active document to paper a4
set counter to counter + 1
end repeat

The script reports: 'paper size of section 1 of active document can't be set to paper a4'
(I had to translate this - I use the Dutch version of Word)

Then I tried:
display dialog (get paper size of section 1 of active document) as string

The script reports 'missing value'.

Any thoughts?

Thanks in advance!

Jan
 
J

John McGhie

Hi Jan:

No, sorry :) I have never written a line of AppleScript. I am afraid you
will have to wait for one of our scripters to happen along.

Should you wish to expedite this process, repost as a new thread with a
provocative heading such as "My AppleScript Doesn't Work" :)

That will attract the people who know what they're talking about :)

Cheers


Hi John,

You said:


I tried this:
set Amount to number of sections of active document
set counter to 1
repeat while counter ≤ Amount
set paper size of section counter of active document to paper
a4
set counter to counter + 1
end repeat

The script reports: 'paper size of section 1 of active document can't be set
to paper a4'
(I had to translate this - I use the Dutch version of Word)

Then I tried:
display dialog (get paper size of section 1 of active document) as string

The script reports 'missing value'.

Any thoughts?

Thanks in advance!

Jan

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
http://jgmcghie.fastmail.com.au/
Sydney, Australia. S33°53'34.20 E151°14'54.50
+61 4 1209 1410, mailto:[email protected]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top