More help with specific page printing

J

Jules

I have a macro set up whereby users are presented with a user form which
gives them the choice of printing all pages, current page or first page OR
inserting into a text box which pages they wish to print. The form also has
a combo box for selecting/inserting the number of copies they wish to print.
Here is the code for the cmdOK button of the form

dim Specific Pages as String
dim NumberCopies as String
SpecificPages = txtSpecPages.value (the name of the text box)
NumberCopies = cboNumCopies.value (the name of the combo box)
If SpecificPages <> "" Then
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages,
Pages:=SpecificPages, Copies:=NumberCopies
ElseIf OptA = True Then (the option button for printing all pages)
ActiveDocument.PrintOut Copies:=NumberCopies
ElseIf OptC = True Then (the option button for printing the current page)
ActiveDocument.PrintOut Range:=wdPrintCurrentPage,
Copies:=NumberCopies
ElseIf OptF = True Then (the option button for printing the first page)
Selection.HomeKey Unit:=wdStory
ActiveDocument.PrintOut Range:=wdPrintCurrentPage,
Copies:=NumberCopies
End If

What happens is the following:
If specific pages is filled in - prints all pages and prints one copy
regardless of how many copies are asked for
If Print All - prints all pages (which is OK) but only prints one copy
regardless of how many copies are asked for
Print Current - prints all pages and only prints one copy regardless of how
many copies are asked for
Print First - prints all pages and only prints one copy regardless of how
may copies are asked for
What am I doing wrong????
The printer I am printing to is set up to print duplex at all times, does
this conflict with the printing request? I would have thought that it would
still print the pages you asked for as duplex.
thanks,
 
B

Bear

Jules:

I'm not going to troubleshoot your code line-by-line, but I do have some
troubleshooting suggestions.

You might try checking the Help to determine the dimension of each parameter
used in the PrintOut method. For example, you've dimensioned SpecificPages as
a string, but the Pages parameter is specified as a variant.

Maybe VBA "handles" this kind of mismatch behind the scenes, but it's one
thing to test out.

Be sure to step through the macro (F8) and point to the different variables
after each step to get a tooltip with the current variable value. Or use the
Immediate window to display those values. Make sure the PrintOut parameters
are getting set the way you intend.

Finally, I don't know if the values are linked in any way to the built-in
Print dialog box. I'm wondering if some of the settings are "sticky" i.e.
derived from the last settings made in the dialog box. Maybe you have to
specify all the arguments to make sure the ones you don't want to use are
nulled.

Bear
 

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