?
Solved

Word Macro to "Scale to Fit"

Posted on 2010-09-16
9
Medium Priority
?
476 Views
Last Modified: 2012-05-10
Hi all, I'm looking to add to a current macro the ability to Fit to Page when printing, the option I believe is Scale to Fit. I just can't figure out the coding for the macro to use Scale to Fit, it should fit on one Letter Size page.

Thanks.
Jon
0
Comment
Question by:Jon DeVito
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 33695574
ActiveDocument.PrintOut PrintZoomPaperWidth:= 72 * 8.5, PrintZoomPaperHeight:= 72 * 11
 

Where 8.5 and 11 are the size in inches
0
 
LVL 3

Author Comment

by:Jon DeVito
ID: 33695749
Thanks Graham. I put it in like below. I get an error on the line: With ActiveDocument.PrintOut under the word .PrintOut

Am I doing this wrong? I tried to follow the same format as the rest of the doc.

Thanks!
Sub PrintAL()
'
' PrintAL Macro
'
'
    Selection.WholeStory
    With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
    With Selection.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = InchesToPoints(0.3)
        .BottomMargin = InchesToPoints(0.2)
        .LeftMargin = InchesToPoints(0.7)
        .RightMargin = InchesToPoints(0.7)
        .Gutter = InchesToPoints(0)
        .HeaderDistance = InchesToPoints(0.5)
        .FooterDistance = InchesToPoints(0.5)
        .PageWidth = InchesToPoints(8.5)
        .PageHeight = InchesToPoints(11)
        .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.PrintOut
        .PrintZoomPaperWidth = 72 * 8.5
        .PrintZoomPaperHeight = 72 * 11
    End With
End Sub

Open in new window

0
 
LVL 3

Author Comment

by:Jon DeVito
ID: 33696014
I tried it this way also. I dont get an error but the resizing options dont look right to me. I attached a pic of what they look like after I run the macro.

Thanks.
Sub PrintAL()
'
' PrintAL Macro
'
'
    Selection.WholeStory
    With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
    With Selection.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = InchesToPoints(0.3)
        .BottomMargin = InchesToPoints(0.2)
        .LeftMargin = InchesToPoints(0.7)
        .RightMargin = InchesToPoints(0.7)
        .Gutter = InchesToPoints(0)
        .HeaderDistance = InchesToPoints(0.5)
        .FooterDistance = InchesToPoints(0.5)
        .PageWidth = InchesToPoints(8.5)
        .PageHeight = InchesToPoints(11)
        .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
    ActiveDocument.PrintOut PrintZoomPaperWidth:=72 * 8.5, PrintZoomPaperHeight:=72 * 11
End Sub

Open in new window

9-16-2010-4-03-19-PM.jpg
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 33696561
I'm not sure what I don't have a printer model whose driver has that tab on the properties dialogue, so I'm not sure what is the problem is.

I see, however that the PageSetup code has already specified the page size to the one that you need, so there should be no need to resize by changing the scale.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 33696572
Sorry. The first sentence should read:

I don't have a printer model whose driver has that tab on the properties dialogue, so I'm not sure what is the problem is.
0
 
LVL 3

Author Comment

by:Jon DeVito
ID: 33697876
Thanks, I dont know why it still runs onto 2 pages sometimes. The only way I found to fix it is either shrink the font even further or click Print Document On &  check the box for Scale to Fit.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 33700017
If you specify the page size in page layout, then Word will format it to fit that page size, not to fit one a particular number of pages.  If the text will normally just fit on one page, then any change, including one to the printer driver could make the page overflow.

If your objective is to confine the document to one page, then, as you have found, reducing the font size is one way to do it.

You could try increasing the page size until it is large enough to hold the text, and then to scale to fit your actual paper size.
Sub FitOnOnePage()
    Const sngInchesWidth As Single = 8.5
    Const sngInchesHeight As Single = 11
    
    With ActiveDocument
        With .PageSetup
                .PageWidth = InchesToPoints(sngInchesWidth)
                .PageHeight = InchesToPoints(sngInchesHeight)
                Do While ActiveDocument.BuiltInDocumentProperties(wdPropertyPages) > 1
                    .PageWidth = .PageWidth * 1.05
                    .PageHeight = .PageHeight * 1.05
                Loop
        End With
        .PrintOut PrintZoomPaperWidth:=sngInchesWidth * 72, PrintZoomPaperHeight:=sngInchesHeight * 72
    End With
End Sub

Open in new window

0
 
LVL 3

Author Comment

by:Jon DeVito
ID: 33717481
Thanks Graham, I will try this one today & let you know.

Thanks.
Jon
0
 
LVL 3

Author Closing Comment

by:Jon DeVito
ID: 33746020
Good enough to get it working for this project. Thanks so much.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question