Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vba for Page SEtup

953 views
Skip to first unread message

Aaron

unread,
Aug 5, 2002, 4:22:57 PM8/5/02
to
I need the code that would be equivalent to the
following:
PAGE SETUP -> MICROSOFT WORD -> APPLY SIZE
AND ORIENTATION TO: WHOLE DOCUMENT

I have a printing problem where the sides are cut off
unless I do the above command. HOwever, since I
have 700 files, I need the vba code to have a macro do
it.

I've tried everything, even the obvious:

for each sec in ActiveDocument.Sections
sec.PageSetup.Orientation=wdOrientPortrait
sec.PageSetup.PageWidth=InchesToPoints(8.5)
sec.PageSetup.PageHeight=InchesToPoints(11)
next sec

This does not work. So does anyone know what I'm
missing?

Thanks,
~Aaron

John McGhie [MVP - Word]

unread,
Aug 10, 2002, 5:26:44 AM8/10/02
to
Hi Aron:

Yes, it will. Notice I changed the active object to "ActiveDocument". This
will apply the formatting change to ALL sections, provided you have NONE
selected.

And sure, the macro recorder errs on the side of obese: just trim out the
stuff you don't need.

Cheers

This responds to microsoft.public.mac.office.word on Tue, 6 Aug 2002
10:27:00 -0700, "Aaron" <aar...@iname.com>:

> Thanks, but no command or group of commands
> seems to work. The document is composed of a few
> sections. I have indeed tried recording myself doing
> the page setup change, but the recorder does not
> catch the important action. If you go to page setup, it
> always ouputs the code to set height, width, and
> orientation. If I change the word menu to say "apply to
> whole document", the macro records the exact same
> thing, so it is obviously not catching this action. And for
> the life of me, I cannot figure out what this action does
> to code it appropriately. If I simply change this one
> drop down menu to say "apply size and orientation to
> whole document", my documents magically print
> effortlessly. But there appears to be no other fix, and
> there appears to be no code to do it... prove me
> wrong?
>
> Thanks,
> ~AAron
>
>
> >-----Original Message-----
> >Hi Aron:
> >
> >The magic incantation is "ActiveDocument" as in:
> >
> > With ActiveDocument.PageSetup
> > .LineNumbering.Active = False
> > .Orientation = wdOrientPortrait
> > .TopMargin = CentimetersToPoints(2.54)
> > .BottomMargin = CentimetersToPoints(2.54)
> > .LeftMargin = CentimetersToPoints(2.5)
> > .RightMargin = CentimetersToPoints(2.5)
> > .Gutter = CentimetersToPoints(0)
> > .HeaderDistance = CentimetersToPoints(1.25)
> > .FooterDistance = CentimetersToPoints(1.25)
> > .PageWidth = CentimetersToPoints(21)
> > .PageHeight = CentimetersToPoints(29.7)
> > .FirstPageTray = wdPrinterDefaultBin
> > .OtherPagesTray = wdPrinterDefaultBin
> > .SectionStart = wdSectionNewPage
> > .OddAndEvenPagesHeaderFooter = False
> > .DifferentFirstPageHeaderFooter = False
> > .VerticalAlignment = wdAlignVerticalTop
> > .SuppressEndnotes = False
> > .MirrorMargins = False
> > .TwoPagesOnOne = False
> > .BookFoldPrinting = False
> > .BookFoldRevPrinting = False
> > .BookFoldPrintingSheets = 1
> > .GutterPos = wdGutterPosLeft
> > End With
> >
> >Hint: always use the Macro Recorder to record these
> things when you are not
> >sure. Word often records work-arounds you could
> spend days looking for.
> >
> >Cheers
> >
> >
> >This responds to microsoft.public.mac.office.word on
> Mon, 5 Aug 2002
> >13:22:57 -0700, "Aaron" <aar...@iname.com>:

> >.
> >

Aaron

unread,
Aug 13, 2002, 10:34:13 AM8/13/02
to
John,
I wish it was this simple. But as I said, I've recorded
myself making the change, and when I run the
recorded macro it does not work. There's nothing to
trim if the thing isn't working. Also, the recorded macro
used ActiveDocument, so that's not it either.

Basically, something is hapenning when I make this
change in Page Setup that is not being recorded by the
macro. Someone else said it may be the PaperSize
attribute, but the sample code:
Documents(1).PageSetup.Papersize=wdPaperLetter
gives a run-time error.

Any other thoughts? or perhaps a recommendation
about how to get rid of the margins error another way?
Thanks,
~Aaron

>.
>

John McGhie [MVP - Word]

unread,
Aug 17, 2002, 6:40:13 AM8/17/02
to
Hi Aaron:

This responds to microsoft.public.mac.office.word on Tue, 13 Aug 2002
07:34:13 -0700, "Aaron" <aar...@iname.com>:

> I wish it was this simple. But as I said, I've recorded
> myself making the change, and when I run the
> recorded macro it does not work.

God this is confusing: What a mess! Microsoft is using Apple's Print
Dialog for this function, and it's ... ummm ... not a good choice!

> There's nothing to
> trim if the thing isn't working.

It *is* working, you just have to know where to look. When you go into
Format Document>Page Setup, you get three settings: Page Attributes,
Microsoft word, and Summary. You must set this to "Microsoft Word" to see
what happened. The "Page Attributes" page reports what paper the printer
driver thinks the printer has, and that never changes.

If you change the paper size within word, Microsoft Word will enable the
"Use custom page size" property in the Microsoft word settings, and then
specify the paper size using the raw primitives Width and Height.

> Basically, something is hapenning when I make this
> change in Page Setup that is not being recorded by the
> macro. Someone else said it may be the PaperSize
> attribute, but the sample code:
> Documents(1).PageSetup.Papersize=wdPaperLetter
> gives a run-time error.

Yeah: That's a bug. It would appear that this mechanism is not available
in OS X, so the VBA constants are not available either and will generate an
error. They know about it, but they can't fix it.

I recorded and tested the following macro in Word v.X. Note: To make it
RECORD the paper size change, it appears that you have to use File>Page
Setup..., or specify the "Microsoft Word" settings in Format>Document.

When the macro runs, the dialog will continue to report the paper size as
A4, but "Use custom page size" is enabled and the paper size is set to the
dimensions for US Letter.

Note the CentimetersToPoints conversion function being recorded: that's
because my system runs in metric. If you set your measurement units to
Points before you record, you will record the raw parameters. There is no
benefit to doing this: Word's native unit is the "Twip" which is a twentieth
of a point, so it's going to convert the measuerments whichever one you use.


Sub Macro1()
'
' Macro1 Macro
' Macro recorded August 17, 2002 by John McGhie
'
With ActiveDocument.PageSetup
.Orientation = wdOrientPortrait
.PageWidth = CentimetersToPoints(21.59)
.PageHeight = CentimetersToPoints(27.94)
End With


With ActiveDocument.PageSetup
.LineNumbering.Active = False

.TopMargin = CentimetersToPoints(2.54)
.BottomMargin = CentimetersToPoints(2.54)
.LeftMargin = CentimetersToPoints(2.5)
.RightMargin = CentimetersToPoints(2.5)
.Gutter = CentimetersToPoints(0)

.HeaderDistance = CentimetersToPoints(1.27)
.FooterDistance = CentimetersToPoints(1.27)
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = True


.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False

.MirrorMargins = True
End With
End Sub

Meantime, I think MS better set its tiny mind to replacing that brain-dead
dialog with one of its own that people can understand.

Hope this helps
All Spam blocked with SpamNet: a free download from http://www.cloudmark.com/

Please post all comments to the newsgroup to maintain the thread.

John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
Sydney, Australia. GMT + 10 Hrs
+61 4 1209 1410, mailto:jo...@mcghie-information.com.au

0 new messages