Writing VBA code for changing page setup

S

Sophie

I need to write VBA code to change the page setup from A4 to quarto when a
certain button is pressed. Is there a shorter code than the one below?

Sub page()
' With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(4)
.BottomMargin = CentimetersToPoints(3.5)
.LeftMargin = CentimetersToPoints(3)
.RightMargin = CentimetersToPoints(2)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.27)
.FooterDistance = CentimetersToPoints(0.81)
.PageWidth = CentimetersToPoints(20.3)
.PageHeight = CentimetersToPoints(25.4)
.FirstPageTray = 116
.OtherPagesTray = 116
.SectionStart = wdSectionContinuous
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.GutterPos = wdGutterPosLeft
End With
End Sub
 
T

Tony Jollans

This looks like recorded code. When recording a macro, Word does not know
what you change in a dialog and so records all the settings - you can (and
should) delete the settings you don't want changed. In this case I guess all
you need keep is:

Sub page()
' With ActiveDocument.PageSetup
.PageWidth = CentimetersToPoints(20.3)
.PageHeight = CentimetersToPoints(25.4)
End With
End Sub

If that doesn't make all the changes you want you may have to either
experiment or look at them each in turn and make a decision based on your
knowledge of your requirements.

I see that the statement "With ActiveDocument.PageSetup" is commented out.
As it won't work like that I presume it is a typo.
 

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