Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-11-2018, 03:31 AM
kiwimtnbkr kiwimtnbkr is offline Macro to Print Custom Range Windows 10 Macro to Print Custom Range Office 2010 64bit
Advanced Beginner
Macro to Print Custom Range
 
Join Date: Oct 2017
Posts: 69
kiwimtnbkr is on a distinguished road
Default Macro to Print Custom Range


Looking for some assistance with code that will allow selected pages of the document the attached code is part of to be printed. (code is courtesy of Allen Wyatt and his word.tip.net postings)

Sometimes it may be only page 85-86, other times it may be pages 3-4, 11-16, 61-80.

It would also be good that if a custom range isn't entered that the entire document is printed.

Code:
Sub PrintNumberedCopies()
    Dim varItem As Variable
    Dim bExists As Boolean
    Dim lCopiesToPrint As Long
    Dim lCounter As Long
    Dim lCopyNumFrom As Long

    ' ensure our doc variable exists
    bExists = False
    For Each varItem In ActiveDocument.Variables
        If varItem.Name = "CopyNum" Then
            bExists = True
            Exit For
        End If
    Next varItem

    ' initialize document variable if doesn't exist
    If Not bExists Then
        ActiveDocument.Variables.Add _
            Name:="CopyNum", Value:=0
    End If

    ' ask how many to print
    On Error GoTo Canceled
    lCopiesToPrint = InputBox( _
        Prompt:="How many copies do you require?", _
        Title:="Print and Number Copies", _
        Default:="1")

    ' ask where to start numbering
    On Error GoTo Canceled
    lCopyNumFrom = CLng(InputBox( _
        Prompt:="Number at which to start numbering copies?", _
        Title:="Print and Number Copies", _
        Default:=CStr(ActiveDocument.Variables("CopyNum") + 1)))

    ' loop through the print-write-print cycle
    For lCounter = 0 To lCopiesToPrint - 1
        ' update the document variable
        ActiveDocument.Variables("CopyNum") = _
            lCopyNumFrom + lCounter
                With Options
                    .UpdateFieldsAtPrint = True
                    .UpdateLinksAtPrint = True
                End With
                    ActiveDocument.Fields.Update
        ' print this numbered copy
        ActiveDocument.PrintOut Copies:=1
    Next lCounter
    
Canceled:
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I print a range of pages? thelighthouse Word 3 03-22-2018 09:50 AM
Fail-safe way to print right page range? New Daddy Word 5 09-22-2013 11:10 PM
Macro to Print Custom Range Print Macro w/ Page Range? stickyit Outlook 1 10-06-2011 09:51 AM
Macro to Print Custom Range Generic range for custom sort macro? tswiers Excel Programming 2 08-11-2011 02:40 AM
Macro to Print Custom Range print range questions A2Irish Excel 1 05-05-2011 05:25 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:08 AM.


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