PDA

View Full Version : DUPLEX PRINT MACRO



Greg
09-10-2009, 11:18 PM
Hi everyone, Your help is required to solve an old problem that went unanswered quite some time ago. In November 2006 danno posted a macro which I subsequently downloaded. Danno couldn't get his document to print in duplex when he ticked the "duplex" option on the Userform. Nor can I. If I could resolve this issue I could make good use of this macro. Jerry had a go at it and so did Ms McKillop. Would anyone care to have another look at this problem for me as it is well beyond my ability at this stage. I wish to attach the macro to this post but I can't see the option here anymore. It's been a while since I participated, has something changed? Regards, Greg.

lucas
09-11-2009, 08:18 AM
click on post reply at the bottom left of the last post and then scroll down and look for 'manage attachments' to attach your file.

Greg
09-13-2009, 12:02 AM
Hi Lucas, It's nowhere to be seen on my screen. I know it's not the easiest place to navigate but I must be doing something very wrong here. Greg.

fumei
09-14-2009, 12:17 PM
Click Go Advanced.

Greg
09-15-2009, 05:35 PM
Thanks Lucas,

The subject macro is attached. This would be a very useful macro if only I could get the double-sided print function to work.

When I tick the double-sided box I get the following message. “Error detected in Macro – Invalid procedure call or argument” I am loathe to play with the code too much (I tried unsuccessfully) and so the attached macro is unaltered save for the labelling.

Any input from you would be greatly appreciated.

Regards,

Greg.

fumei
09-16-2009, 10:41 AM
"“Error detected in Macro – Invalid procedure call or argument”

Indeed there are.

1. There are a number of:
Call CopyMemory


Have you actually looked at this Sub?

2. You also have this:
If CheckBox1.Value = True Then
MyPrinter = Left(Word.ActivePrinter, _
InStr(1, Word.ActivePrinter, " on NE02:") - 1)
SetPrinterDuplex MyPrinter, 1
CheckBox1.Value = False
End If

which, as you can tell easily, means the Duplex checkbox is checked.

Have you actually tried debugging, and looking at values? In the code
SetPrinterDuplex MyPrinter, 1
do you know what MyPrinter comes out as?

SetPrinterDuplex requires a printer names as a parameter
Function SetPrinterDuplex(ByVal sPrinterName As String,


So MyPrinter is passed to SetPrinterDuplex as a string parameter.

What does MyPrinter becomes with:
MyPrinter = Left(Word.ActivePrinter, _
InStr(1, Word.ActivePrinter, " on NE02:") - 1)
? Did you look?

My printer is: Xerox WorkCentre 255 ITTB on NE00:

Now if I change the code to be:
MyPrinter = Left(Word.ActivePrinter, _
InStr(1, Word.ActivePrinter, " on NE00:") - 1)
I get no error. But, if I keep it at NE02: - which is hard coded, then I get:

“Error detected in Macro – Invalid procedure call or argument”

Why? Because
InStr(1, Word.ActivePrinter, " on NE02:") - 1)
returns a value of -1. There is no "NE02:" - it is NE00 - so InStr returns a -1.

Which means it becomes:
Left(Word.ActivePrinter, -1)
Left does not allow this.

So, while there may be other errors (and I think there are), you could try:
MyPrinter = Left(Word.ActivePrinter, _
InStr(1, Word.ActivePrinter, " on") - 1)
getting rid of the hard coded "NE02:". If you need "NE02:" for some reason, use it as a separate piece of logic.

You are still not having Option Explicit as a default. I strongly suggest you do.

The Sub Sub okbutton_Click() - has TWO - repeat TWO - identical pieces of code, the test against the checkbox. So it does it twice.

If you comment out one (or remove it), AND you change it to:
'Duplex Printing
If CheckBox1.Value = True Then
MyPrinter = Left(Word.ActivePrinter, _
InStr(1, Word.ActivePrinter, " on") - 1)
SetPrinterDuplex MyPrinter, 2
End If
then indeed SetPrinterDuplex does execute without the error.

However, nothing happens. Why? Because SetPrinterDuplex returns a Boolean, true or false. That is it.

Greg
09-16-2009, 08:56 PM
Well done Gerry. You are very good at your job. I have one more question for you. How do you change the smiley face and initials on the Word 2007 ribbon for this macro? I am finally getting used to the ribbon but I still use the UbitMenu add-in for the old menu style quite often. Customising the ribbon is challenging. I hope MS make it easier sometime soon. Many thanks, Greg.

fumei
09-17-2009, 08:43 AM
There is a separate forum here that deals only with Ribbon issues. Take a look there and you may find something. I do not use, and will not use, 2007, so it is a moot point for me.