Print only certain pages in Form

D

dgold82

Is there a way to make a checkbox that when checked clicking print would only
print those pages? I have a document with 50 forms in it and would like to
put a little box in the corner so that if it is checked word will only print
those pages.

Any ideas?
 
G

Graham Mayor

If you put a check box on each page (not in the header) and name those check
boxes P1 to P50 then the following macro will print those pages on which the
check box is checked.

For i = 1 To 50
If ActiveDocument.FormFields("P" & i).CheckBox.Value = True Then
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages,
Pages:=format(i), Copies:=1
End If
Next i

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

dgold82

Hi Graham,

I think I spoke a little too soon. Can you please provide a little more
instructions with this one. I'm not sure I'm putting in the code correctly or
if I'm putting it in the right place. I also assume you are talking about the
active X checkbox? Thx
 
G

Graham Mayor

No I am talking about form field checkboxes and the macro is stored in the
form template and run on exit from each of the check box fields which should
be named P1 to P50 (or whatever the last number is). I would avoid the use
of activeX fields in protected forms. They create more problems than they
solve.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

dgold82

OK, so I am testing this on a 2 page form and this is what I put in as a
macro and named one checkbox "P1" (as the bookmark) and the other as P2. The
P1 checkbox is on the first page and the P2 checkbox is on the second. It
didn't work. I then tried removing the "Sub PrintOnly()" "End Sub" and that
didn't work. What am I doing wrong? The other macro codes you gave me are
working great.

Sub PrintOnly()

For i = 1 To 2
If ActiveDocument.FormFields("P" & i).CheckBox.Value = True Then
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages,
Pages:=format(i), Copies:=1
End If
Next i


End Sub
 
G

Graham Mayor

There is a premature wrap in the line beginning 'Then' which could be your
problem. Correct that or use

Sub PrintOnly()
For i = 1 To 2
If ActiveDocument.FormFields("P" & i).CheckBox.Value = True Then
ActiveDocument.PrintOut _
Range:=wdPrintRangeOfPages, _
Pages:=format(i), _
Copies:=1
End If
Next i
End Sub

instead

I take it you locked the form?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

dgold82

I got this one to work. The only problem is that is automatically begins
printing the page when I leave the checkbox field (it calculates on exit). I
was thinking that I would just check all the boxes on the pages that I want
and then at the end clicking print and it would only print those pages.

So basically this document is going to have 50 forms in it. For each given
record we would only need about 5-10 of them. We would leave those 5-10 forms
checked from your macro below and then whenever we want to print them we
would just click print and it would print those 5-10 forms whenever we needed
them. The macro you gave basically acts like a "print this page" type of
button. Does that makes sense. I really appreciate your help with this but I
also don't want to take too much more of your time if I am not being clear.

Thank again!
 
G

Graham Mayor

It sounds like you are running the macro on exit from the check box field.
Run it from a custom toolbar button.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Terry Farrell

This really sounds like an over-the-top complex solution. Why not have a
single template comprising a a front page displaying a list of available
forms (with a brief description of each if required) and a check box at the
side of each. The user then clicks a check box which fires a macro to add
the form as a new section to the current document. This will simplify the
document and make it much smaller as it will only contain 5 to 10 forms
instead of 50 plus forms and a few macros. It will be easier to handle and
search too and if the forms get updated, only the linked form will need
updating.
 
D

dgold82

Hi Terry! That was my thinking at first until I couldn't find a macro code to
do that. I asked how on this message board (in "new users" on 12/8/08) and
was told it was too complex. If you can provide me with some code and
instruction I would be very grateful. Either way--a big thank you to Graham
and to you!
 
T

Terry Farrell

....and if Graham's examples still leave you short of your requirement, post
a question ion the appropriate Word.VBA newsgroup where the developers hang
out.

Terry
 

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