[blue]Sub PrintSpecial()
Dim rc As Long
With Application.Dialogs(wdDialogFilePrint)
On Error Resume Next
Do
Err.Number = 0
rc = .Display
If Err.Number <> 0 Then
MsgBox "You had an error: """ & Err.Description & """" & vbNewLine & _
"Unfortunately Word has not given me the correction you made." & _
vbNewLine & vbNewLine & _
"Would you be so kind as to re-enter your requirements?"
End If
Loop Until Err.Number = 0
On Error GoTo 0
If rc = -1 Then ' OK
.Pages = ReBuild(.Pages)
.Execute
End If
End With
End Sub
Function ReBuild(strPages As String) As String
Dim vPageRanges As Variant
Dim vPageNumbers As Variant
Dim iPageNumber As Integer
Dim i As Integer, j As Integer
Dim rng As Range
[green]
' N.B. Input IS syntactically valid; the Dialog doesn't cede control until it is.
' Input is not necessarily 'sensible' but the Print itself deals with that.
[/green]
vPageRanges = Split(strPages, ",")
For i = 0 To UBound(vPageRanges)
vPageNumbers = Split(vPageRanges(i), "-")
For j = 0 To UBound(vPageNumbers)
If vPageNumbers(j) <> "" Then
iPageNumber = CInt(vPageNumbers(j))
If iPageNumber <= Selection.Information(wdNumberOfPagesInDocument) Then
Set rng = Selection.Range.GoTo(What:=wdGoToAbsolute, Count:=iPageNumber)
vPageNumbers(j) = "p" & rng.Information(wdActiveEndAdjustedPageNumber) & _
"s" & rng.Information(wdActiveEndSectionNumber)
End If
End If
Next
vPageRanges(i) = Join(vPageNumbers, "-")
Next
ReBuild = Join(vPageRanges, ",")
End Function[/blue]