Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple copies for one Printout Command

Status
Not open for further replies.

gregoriw

Programmer
Sep 21, 2001
40
US
I'm working with the msOutL9.olb module to automate various Outlook functions inside my VB 6 program. One of these functions is to print an email message. It is a relatively easy command to execute but when I go to the printer to pick up the output, I find that 4 copies of the same message is printed. I only want one copy not 4.

Is there something to reset in the default printer settings?

Here is my code (simple and sweet) that tells outlook to print the message.
------------------------
Private Sub PrintEmail(ByVal intSelRow As Integer)

Dim olThisItem As MailItem

On Error GoTo ErrHandler

'get specific item
Set olThisItem = AllMessages.Item(intSelRow)
'print me
olThisItem.PrintOut

Set olThisItem = Nothing

Exit Sub

ErrHandler:
MsgBox "oops! in PrintEmail"

End Sub

NOTE: AllMessages is a collection of all Inbox folder messages previously recovered in another module.
------------------------

Any ideas or hints would be welcome.

Thank you,
Wolfgang
 
If you go to file-print, does the dialog show 4 as the number of copies?
Rob
[flowerface]
 
My app does not have any printer/setup options in it, but I did go to several other programs (Word, IE, SQL Query Analyzer, ETC.) and each them have the number of copies option set to 1. So I suspect the printer settings on my PC have reset themselves to 1. Something else is triggering the number of copies to 4.

I've read through other threads on Tek-Tips and I found something where a Word VBA module issued a call to PrintOut with additional parameters suchs as

.Printout,,,,,,,,1

where 1 supposedly is the number of copies requested.

Did you know about this? Is it necessary to force a number of copies value with the PrintOut method?
 
The PrintOut method in OL has no such parameters - VBA help states that it uses the "default settings" to print the item. My guess is that some users have previously chosen to print more copies, and that number of copies is retained as the "default". Just a wild guess, though.
Rob
[flowerface]
 
I've never combined VB with VBA but is it possible to access the printer settings and set them prior to printing ie
Code:
oPrinter.Copies = 1

Just a thought!??

;-) If a man says something and there are no women there to hear him, is he still wrong?
 
I don't think Outlook has a printer object. Outlook VBA is kind of limited, compared to XL and WD.
Rob
[flowerface]
 
Not sure what you're relating to because when I print a simple text file or another email message to the same printer that my app (which prints 4 copies) prints to, only one copy prints. And this happens immediately after I test my app again.

Sounds like something else relating to my app's code is the culprit. I've tried tracing/debugging single step through the code and cannot tell where it indicates that the number of copies gets changed.

Wolfgang
 
I just confirmed my suspicion: I went into Outlook, and using the File-Print dialog, printed two copies of a mail item. Then I printed a different mail item using the .printout method. Two copies printed. So whatever the number of copies last selected by the user is what gets used by the .printout method. I don't know of a means of setting the number of copies through Outlook VBA.
Rob
[flowerface]
 
OK, I'm no programmer but I would be interested now to know if setting the default number of printouts in the VB portion of your program will work.

As Rob correctly pointed out there is no printer object in outlook VBA (in fact there is no printer object throughout VBA, as the application's printer object is used) However what I'm suggesting is using the pure VB command to set the number of printouts prior to calling outlook's PrintOut method.

The way I'm thinking is
Code:
oMyPrinter.Copies = 1
olThisItem.PrintOut

As I said before, it's just a thought, but one I'm unable to test at the moment.

Happy Friday
;-) If a man says something and there are no women there to hear him, is he still wrong?
 
The number of copies (in fact, any custom printer settings) are maintained locally within the application doing the printing. For example, when I chose the two copies in Outlook, and then printed from Word, Word only printed one copy - but going back to Outlook and printing programmatically, two copies were printed. Similarly, if I activate two-sided printing in Word (via the print options dialog), it remains at that setting for as long as I keep Word open - but it does not change the setting for printing from other documents. So I don't think there is a universal printer object that governs these settings.
Loomah, how does the printer object in VB work? Have you been able to use it to change print settings in other applications?
Rob
[flowerface]
 
This is a great little discussion thread. Glad we're all learning from each other about one of the quirky things about Windows, VBA, and printing.

I've taken each of your most welcome ideas about what to try and here is a recap of where my testing is now. Let me fist mention that my setup is as follows:

- on a network with about 200 computers each using a networked printer. No one has a local printer.
- we have a dedicated print server/manager handling all print requests to various networked printers. (I had been printing/testing to only our departments main printer. IE. "printer a")
- running WIN NT 4 sp 6
- programming with VB6 and made a reference to the msoutl9.olb module

Today, I tried an alternate approach to testing and this is how it went.

- hand checked the Registry with RegEdit looking for anything that might store "Copies =4" or "PrinterSettings" but could not find anything (or did not find the right registry key)

- added Printer.Copies = 1 and no change was detected. Still printed 4 copies.

- changed my default printer from "printer a" to "printer b". printed sample text file to ensure that my default printer setting was now engaged. only 1 copy of test file printed.

- ran my app which has the hook to the outlook library module, selected email message/item to print and guess what? 4 copies printed on "printer a" even though my windows default printer was "printer b"!!!!

- changed default printer back to "printer a", ran app, selected and printed item, and now the output ended up on "printer b" (my previous default printer). Getting strange here!

- next I decided that it might be a good time to reboot my pc.

- once everything was back up, ran my app, printed an item and now it printed to my default "printer b" just one time. Just as I wanted it to.

So after all that back and forth testing, I still don't really understand what happened other than to agree with Loomah that the printer settings and VBA don't really talk directly to each other. I may have just "reset" my PC by accident to a default printer setting of only 1 copy per request.

At this time all I can think of is to give everyone a big pat on the back for helping me out. I encourage all to continue this thread if there are other suggestions or solutions to this issue because I know that I'm not the only one to have experienced this quirk.

I'll continue checking with the Microsoft support site or Sue Mosher's columns/werb site to see if they have an answer in how to manipulate printing from Outlook and VBA/VB.

Thanks,
Wolfgang
 
I found one way to reset the number of copies without actually printing, using the keystroke combination in Outlook:

ctrl-P alt-C (number of copies) alt-V alt-C
to open the print dialog, set the number of copies, go to print preview, and close print preview. Unfortunately, I don't know how to use sendkeys to send that string to the outlook application.
Rob
[flowerface]
 
RobBroekhuis & gregoriw:

I realize that this is not related with regards to printing, but I worked on an Excel project to send E-mail based on information in an Excel spreadsheet and after some research, trial, and error I discovered this method. Perhaps you could use the same method to send RobBroekhuis's Ctrl-P Alt-C (Number of Copies) Alt-V Alt-C as
Code:
^p%s1%v%c
.

Code:
Sub
Code:
 SendEmail()
Code:
'Assign E-mail Address
Code:
  sEmail = "E-mail@Address.com"
Code:
'Assign E-mail Subject
Code:
  sSubj = "Sample Subject"
Code:
'Replace Spaces With %20 (HEX)
Code:
  sSubj = Application.WorksheetFunction.Substitute(sSubj, " ", "%20")
  sMsg = Application.WorksheetFunction.Substitute(sMsg, " ", "%20")
Code:
'Replace Carriage Returns With %0D%0A (HEX)
Code:
  sMsg = Application.WorksheetFunction.Substitute(sMsg, vbCrLf, "%0D%0A")
Code:
'Create URL
Code:
  sURL = "mailto:" & sEmail & "?subject=" & sSubj & "&body=" & sMsg
Code:
'Execute URL (Start E-mail Client)
Code:
  ShellExecute 0&, vbNullString, sURL, vbNullString, vbNullString, vbNormalFocus
Code:
'Wait One Second Before Sending Keystroke
Code:
  Application.Wait (Now + TimeValue("0:00:01"))
Code:
'Send Ctrl+K To Check Email Name
Code:
  Application.SendKeys "^k"
Code:
'Wait One Second Before Sending Keystroke
Code:
  Application.Wait (Now + TimeValue("0:00:01"))
Code:
'Send Alt+S To Send E-mail
Code:
  Application.SendKeys "%s"
Code:
End Sub

Regards, LoNeRaVeR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top