Print Specific Pages

G

Guest

We have all of our printers set up to print to duplex printing. I am trying
to set up a macro so that when a user wants to print a current page, it will
print the current page and next page if the current page is an odd number or
the previous page and the current page if the current page is an even number.
I have set up the following, but get a "type mismatch" error when it gets to
the actual "printout".

Private Sub OurPrintOut()
Dim IngPN As Long
Dim IngCheck As Long
Dim FollowingPage As Long
Dim PreviousPage As Long
Dim ThisPage As String
Dim TotalPages As Long
ActiveDocument.Bookmarks.Add Range:=Selection.Range, name:="BackHere"
Selection.EndKey unit:=wdStory
TotalPages = Selection.Information(wdActiveEndPageNumber)
ActiveDocument.Bookmarks("BackHere").Select
IngPN = Selection.Information(wdActiveEndPageNumber)
IngCheck = IngPN Mod 2
If IngCheck > 0 Then
ThisPage = "odd"
ElseIf IngCheck <= 0 Then
ThisPage = "even"
End If
FollowingPage = IngPN + 1
PreviousPage = IngPN – 1
ActiveDocument.Bookmarks("BackHere").Select
If TotalPages > 1 Then
If ThisPage = "odd" Then
ActiveDocument.PrintOut Range:=wdPrintFromTo, From:=IngPN, To:=FollowingPage
ElseIf ThisPage = "even" Then
ActiveDocument.PrintOut Range:=wdPrintFromTo, From:=PreviousPage, To:=IngPN
End If
ElseIf TotalPages < 2 Then
ActiveDocument.PrintOut
End If
End Sub

I have checked that the result of all the definitions is correct, by this I
mean that if I am on page 4 of a 7 page document:
IngPN returns " 4"
FollowingPage returns " 5"
PreviousPage returns " 3"
ThisPage returns "even"
TotalPages returns " 7"
I don't know if the space before each number is significant
Could someone please help me with this
thanks
 
J

Jezebel

You've been stymied by Microsoft's cruddy documentation. Although the From
and To arguments are documented as type variant, which in context implies
that they may be longs as you have them, in practice they need to be
strings. (This is so the function can support page specifications like
"s3p4".) Try

ActiveDocument.PrintOut Range:=wdPrintFromTo, From:=cstr(IngPN),
To:=cstr(FollowingPage)
 

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