Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-26-2022, 10:38 PM
Peterson Peterson is offline Macro for page setup Windows 10 Macro for page setup Office 2019
Competent Performer
 
Join Date: Jan 2017
Posts: 143
Peterson is on a distinguished road
Default

Try this:
Code:
Sub PageSize_SetVarious() ' 01/26/2022

    Dim strPageSize As String
    Dim strPageWidth As String, strPageHeight As String, strTopMargin As String, _
    strBottomMargin As String, strLeftMargin As String, strRightMargin As String, _
    strHeaderDistance As String, strFooterDistance As String
    
    ' Prompt user for page size:
    strPageSize = InputBox("Enter the page size you want (enter the numeral):" & _
    vbCrLf & vbCrLf & " 1.    5.5 x 8.5" & vbCrLf & " 2.    6 x 9" & _
    vbCrLf & " 3.    6.14 x 9.21" & vbCrLf & " 4.    7 x 10" & _
    vbCrLf & " 5.    8.25 x 11" & vbCrLf & _
    vbCrLf & "Specify Page Size:")

    ' If user cancels, exit sub:
    If strPageSize = vbNullString Then
        Exit Sub
    End If
    
    Select Case strPageSize
    
        ' Modify the margin and header/footer values to your needs.
        ' If you don't need to, delete these lines from each Case,
        ' and as noted below.
        Case 1 ' 5.5 x 8.5
            strPageWidth = "5.5"
            strPageHeight = "8.5"
            
            strTopMargin = "0.3"
            strBottomMargin = "0.3"
            strLeftMargin = "0.3"
            strRightMargin = "0.3"
            strHeaderDistance = "0.2"
            strFooterDistance = "0.2"
        Case 2 ' 6 x 9
            strPageWidth = "6"
            strPageHeight = "9"
            
            strTopMargin = "0.3"
            strBottomMargin = "0.3"
            strLeftMargin = "0.3"
            strRightMargin = "0.3"
            strHeaderDistance = "0.2"
            strFooterDistance = "0.2"
        Case 3 ' 6.14 x 9.21
            strPageWidth = "6.14"
            strPageHeight = "9.21"
            
            strTopMargin = "0.3"
            strBottomMargin = "0.3"
            strLeftMargin = "0.3"
            strRightMargin = "0.3"
            strHeaderDistance = "0.2"
            strFooterDistance = "0.2"
        Case 4 ' 7 x 10
            strPageWidth = "7"
            strPageHeight = "10"
            
            strTopMargin = "0.3"
            strBottomMargin = "0.3"
            strLeftMargin = "0.3"
            strRightMargin = "0.3"
            strHeaderDistance = "0.2"
            strFooterDistance = "0.2"
        Case 5 ' 8.25 x 11
            strPageWidth = "8.25"
            strPageHeight = "11"
            
            strTopMargin = "0.3"
            strBottomMargin = "0.3"
            strLeftMargin = "0.3"
            strRightMargin = "0.3"
            strHeaderDistance = "0.2"
            strFooterDistance = "0.2"
    End Select
        
    Selection.WholeStory
    
    ' If you don't need to set margins/headers/footers,
    ' then delete those lines below:
    With ActiveDocument.PageSetup
        .PageWidth = InchesToPoints(strPageWidth)
        .PageHeight = InchesToPoints(strPageHeight)
        
        .TopMargin = InchesToPoints(strTopMargin)
        .BottomMargin = InchesToPoints(strBottomMargin)
        .LeftMargin = InchesToPoints(strLeftMargin)
        .RightMargin = InchesToPoints(strRightMargin)
        .HeaderDistance = InchesToPoints(strHeaderDistance)
        .FooterDistance = InchesToPoints(strFooterDistance)
    End With
End Sub
Reply With Quote
 

Tags
vba code, word 16 page layout



Similar Threads
Thread Thread Starter Forum Replies Last Post
documents print setup defined in page setup, but overriden by printer settings. macro required? Rosemary Word VBA 6 02-18-2021 11:10 PM
Macro for page setup Page setup before working luca155 PowerPoint 1 08-30-2012 12:06 PM
Page setup problem glenvern Word 1 09-19-2011 05:01 AM
Page Setup gus PowerPoint 0 03-09-2010 09:51 PM
Page Setup Ryan Word 0 01-24-2007 10:42 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:25 PM.


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