Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Macros in Outlook 2010

Posted on 2013-06-12
6
Medium Priority
?
684 Views
Last Modified: 2013-07-09
I need to create a macro that prints duplex when printing emails. Anyone know how I can do this?
0
Comment
Question by:philwood12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 16

Accepted Solution

by:
terencino earned 1500 total points
ID: 39246713
Outlook can't access the printer settings with native VBA, and has only the PrintOut function which prints to whatever settings the default printer has. It doesn't have ActivePrinter or Application.Printer like the other Office apps. I've tried a few samples of Windows API functions like Changing Printer settings using the Windows API and had no success with network printers, but maybe they work Ok with local printers.

Another option might be to set up two printers with the same driver but different names, one set up with duplex and the other without, and use the registry to change from one to the other. Chip Pearson has done all the hard work for registry functions in VBA. Copy the two modules in the Excel file to your Outlook VBE.

The registry names of all your printers are located at:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices
Default printer is the Device value located at:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows

Here is some code you could use to print the selected email out to the duplex printer, then switch back to the default. Just need the registry name for DuplexPrinter = "Name_of_duplex_printer"

Sub PrintToDuplexPrinter()
 Dim myOlExp As Outlook.Explorer
 Dim myOlSel As Outlook.Selection
 Dim oMail As Outlook.mailItem
 Dim x As Long
 Set myOlExp = Application.ActiveExplorer
 Set myOlSel = myOlExp.Selection
BaseKey = HKEY_CURRENT_USER
KeyName = "Software\Microsoft\Windows NT\CurrentVersion\Windows"
ValueName = "Device"
DefaultPrinter = RegistryGetValue(BaseKey, KeyName, ValueName)
DuplexPrinter = "Name_of_duplex_printer"
'Change to duplex printer
RegistryUpdateValue BaseKey, KeyName, ValueName, DuplexPrinter
'Print out each email selected
 For x = 1 To myOlSel.count
  If myOlSel.Item(x).Class = OlObjectClass.olMail Then
    Set oMail = myOlSel.Item(x)
    oMail.PrintOut
  End If
 Next x
'Reinstate original default printer
RegistryUpdateValue BaseKey, KeyName, ValueName, DefaultPrinter
End Sub

Open in new window

Good luck!
...Terry
0
 
LVL 21
ID: 39248270
For applications that do not allow you to control the print, like Outlook and other business software, I set up multiple copies of the same printer. Each with different default printing preferences.

 Example names in the printer list: HP4200 Legal, HP4200 Legal Duplex, etc.

When you print, you select the print that has the settings you want.

I started doing this back with Windows 3.1. Works great.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:philwood12
ID: 39306841
Hi Terry.  I tried your VB code, but I keep getting a Compile error: Sub or Function not defined message at RegistryGetValue. Any ideas?
0
 
LVL 16

Expert Comment

by:terencino
ID: 39309638
Sure, did you have a look at:
...Chip Pearson has done all the hard work for registry functions in VBA. Copy the two modules in the Excel file to your Outlook VBE....
The RegistryGetValue is part of those modules
Cheers...Terry
0
 

Author Comment

by:philwood12
ID: 39309667
Hi Terry.  Which  two modules? The modGetSystemErrorMessage Text and modRegistry modules?
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question