Document length and print options

I

Ithaca

I'm setting up a macro for form printing and I need help with the final
details.

1. How would you go about determining a document's length and default the
auto print to exclude the last page.

2.Then giving the user the option (via InputBox) for including the last page.

Thanks in advance for any help!

-ithaca
 
J

Jezebel

Select case Msgbox("Do you want to print the last page?", vbYesNoCancel)
Case vbYes
ActiveDocument.Printout
Case vbNo
ActiveDocument.Printout From:=1,
To:=activedocument.BuiltInDocumentProperties("Number of pages") - 1
Case else
End select
 
I

Ithaca

Thanks for the help. That works great! Would I be able to somehow save that
response to use later in the macro? I want to replace the current directions
to print, namely the page range, to this "omit last page" range.
Here's the macro that I'm trying to apply it to:

Sub FormPrint()

Dim NumCopies As String
Dim StartNum As String
Dim Counter As Long
Dim oRng As Range

If MsgBox("The copy number will appear at the insertion point." _
& " Is the cursor at the correct position?", _
vbYesNo, "Placement") = vbNo Then End
If ActiveDocument.Saved = False Then
If MsgBox("Do you want to save any changes before" & _
" printing?", vbYesNoCancel, "Save document?") _
= vbYes Then
ActiveDocument.Save
End If
End If
StartNum = Val(InputBox("Enter the starting number.", _
"Starting Number", 6))
NumCopies = Val(InputBox("Enter the number of copies that" & _
" you want to print", "Copies", 1))
ActiveDocument.Bookmarks.Add Name:="CopyNum", Range:=Selection.Range
Set oRng = ActiveDocument.Bookmarks("CopyNum").Range
Counter = 0
If MsgBox("Are you sure that you want to print " _
& NumCopies & " numbered " & " copies of this document", _
vbYesNoCancel, "On your mark, get set ...?") = vbYes Then
While Counter < NumCopies
oRng.Delete
oRng.Text = StartNum
Dim sCurrentPrinter As String
Dim sFormPrint As String

sCurrentPrinter = Application.ActivePrinter

Application.ActivePrinter = "\\apd-print2\05025_82_9k on NE01:"

Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="1-3", PageType:= _
wdPrintAllPages, ManualDuplexPrint:=False, Collate:=False,
Background:= _
True, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, _
PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0

Application.ActivePrinter = sCurrentPrinter
StartNum = StartNum + 1
Counter = Counter + 1
Wend
End If
End Sub
 
J

Jezebel

You can save the result of the MsgBox function into a variable --

Dim pMsgResult as long
pMsgResult = MsgBox(...)

However, with all those questions, better to use a UserForm with all the
questions presented to the user at once.


Separately, never use End the statement. It's included only for backward
compatability with antedeluvian Basic, and these tends to cause bugs and
crashes. Use Exit Sub to abort a procedure, or re-structure the logic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top