Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-19-2020, 05:13 AM
dita dita is offline Change Page size Windows XP Change Page size Office 2010 64bit
Advanced Beginner
Change Page size
 
Join Date: Apr 2018
Posts: 34
dita is on a distinguished road
Default Change Page size

Hello!


I have used the macro recorder to change the page size of a document to A4 but I got the largest code ever to do this simple change.


Is there any way to change page without the need of including such large lines of code?


This is what I got from the macro recorder:


Sub Macro1()
'
' Macro1 Macro
'
'
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(2.5)
.BottomMargin = CentimetersToPoints(2.5)
.LeftMargin = CentimetersToPoints(3)
.RightMargin = CentimetersToPoints(3)
.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


.SectionDirection = wdSectionDirectionLtr
.LayoutMode = wdLayoutModeDefault
End With
End Sub
Reply With Quote
  #2  
Old 05-19-2020, 05:29 AM
Guessed's Avatar
Guessed Guessed is offline Change Page size Windows 10 Change Page size Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The relevant lines from your code is:
Code:
Sub Macro1()
  With Selection.PageSetup
    .PageWidth = CentimetersToPoints(21)
    .PageHeight = CentimetersToPoints(29.7)
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 05-19-2020, 05:58 AM
macropod's Avatar
macropod macropod is offline Change Page size Windows 7 64bit Change Page size Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Simpler:
Code:
Sub Demo()
Selection.PageSetup.PaperSize = wdPaperA4
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 05-19-2020, 06:13 AM
dita dita is offline Change Page size Windows XP Change Page size Office 2010 64bit
Advanced Beginner
Change Page size
 
Join Date: Apr 2018
Posts: 34
dita is on a distinguished road
Default

Thanks Guessed. Thatīs exactly what I was looking for
Reply With Quote
  #5  
Old 05-19-2020, 07:04 PM
Guessed's Avatar
Guessed Guessed is offline Change Page size Windows 10 Change Page size Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

If you wanted to use Paul's simpler option, you may also need to include an orientation line to specify either Portrait or landscape layout
Selection.PageSetup.Orientation = wdOrientPortrait
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom page size - Page color not covering entire page when converting to PDF icor1031 Word 9 12-09-2019 08:21 PM
Change page size reducing both margins WizardDani Word 1 01-04-2018 06:41 AM
Change Page size Configured page size to 20 inches height : why the page still breaks @ the default 9,6” ? Ron Wolpa Word 4 08-18-2016 06:43 PM
Change Page size Change Default Zoom Size to 'Page Width' tyger330 Word 9 12-19-2012 07:50 AM
Change Page size how change size font to inches size kkepo Word 4 08-28-2012 08:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:02 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft