Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Writing VBA code for changing page setup

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sophie - 28 Sep 2006 05:57 GMT
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
Tony Jollans - 28 Sep 2006 06:26 GMT
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.

--
Enjoy,
Tony

> 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?
[quoted text clipped - 24 lines]
>     End With
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.