Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-20-2019, 03:40 AM
gloub gloub is offline Toggle A4 and Custom size Windows 7 64bit Toggle A4 and Custom size Office 2003
Novice
Toggle A4 and Custom size
 
Join Date: Feb 2018
Location: Paris, France
Posts: 29
gloub is on a distinguished road
Default Toggle A4 and Custom size

Hello Forum!


I'd like to write a macro that allows me to change the paper size as follows:
– If the document's format is A4, switch to Custom Size
– If the document's format is Custom Size, switch to A4

...but I don't know how to do proceed.
Could someone help me?

Thanks !
Reply With Quote
  #2  
Old 01-20-2019, 02:42 PM
macropod's Avatar
macropod macropod is offline Toggle A4 and Custom size Windows 7 64bit Toggle A4 and Custom 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

Have you tried recording what you want with the macro recorder? Without knowing what the custom size is, no-one here could write the macro for you.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-20-2019, 03:33 PM
gloub gloub is offline Toggle A4 and Custom size Windows 7 64bit Toggle A4 and Custom size Office 2003
Novice
Toggle A4 and Custom size
 
Join Date: Feb 2018
Location: Paris, France
Posts: 29
gloub is on a distinguished road
Default

Hi, and thanks for answering.

Here is what I got from the macro recorder (first when I change from Custom to A4, and then back to Custom size).

Code:
Sub Toggle_Paper_size()
'
    With ActiveDocument.Styles(wdStyleNormal).Font
        If .NameFarEast = .NameAscii Then
            .NameAscii = ""
        End If
        .NameFarEast = ""
    End With
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(0.63)
        .BottomMargin = CentimetersToPoints(0.5)
        .LeftMargin = CentimetersToPoints(0.95)
        .RightMargin = CentimetersToPoints(0.63)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(0)
        .FooterDistance = CentimetersToPoints(0)
        .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
    With ActiveDocument.Styles(wdStyleNormal).Font
        If .NameFarEast = .NameAscii Then
            .NameAscii = ""
        End If
        .NameFarEast = ""
    End With
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(0.63)
        .BottomMargin = CentimetersToPoints(0.5)
        .LeftMargin = CentimetersToPoints(0.95)
        .RightMargin = CentimetersToPoints(0.63)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(0)
        .FooterDistance = CentimetersToPoints(0)
        .PageWidth = CentimetersToPoints(45.89)
        .PageHeight = CentimetersToPoints(55.87)
        .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
End Sub
Thanks for helping.
Reply With Quote
  #4  
Old 01-20-2019, 04:31 PM
Guessed's Avatar
Guessed Guessed is offline Toggle A4 and Custom size Windows 10 Toggle A4 and Custom 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

try this
Code:
Sub Toggle_Paper_size()
  With ActiveDocument.Styles(wdStyleNormal).Font
    If .NameFarEast = .NameAscii Then .NameAscii = ""
    .NameFarEast = ""
  End With
  With ActiveDocument.PageSetup
    .LineNumbering.Active = False
    .Orientation = wdOrientPortrait
    .TopMargin = CentimetersToPoints(0.63)
    .BottomMargin = CentimetersToPoints(0.5)
    .LeftMargin = CentimetersToPoints(0.95)
    .RightMargin = CentimetersToPoints(0.63)
    .Gutter = CentimetersToPoints(0)
    .HeaderDistance = CentimetersToPoints(0)
    .FooterDistance = CentimetersToPoints(0)
    .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
    If .PaperSize = wdPaperA4 Then
      .PageWidth = CentimetersToPoints(45.89)
      .PageHeight = CentimetersToPoints(55.87)
    Else
      .PaperSize = wdPaperA4
    End If
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 01-20-2019, 05:00 PM
gloub gloub is offline Toggle A4 and Custom size Windows 7 64bit Toggle A4 and Custom size Office 2003
Novice
Toggle A4 and Custom size
 
Join Date: Feb 2018
Location: Paris, France
Posts: 29
gloub is on a distinguished road
Default

It works perfectly !!!!!
Thank you so much :^)
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom page size settings ibclare Publisher 0 10-27-2014 08:34 PM
Toggle A4 and Custom size Toggle objects on / off with custom toolbar Milon Word VBA 3 07-23-2013 06:21 AM
Toggle A4 and Custom size Custom label size for merge dmwesq Mail Merge 13 04-24-2011 02:36 PM
Toggle A4 and Custom size Saving custom page size comptech Word 2 10-05-2010 06:01 AM
Printing Custom Size Pages vicktown Word 0 10-21-2009 12:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:08 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