Solved

Macros in Outlook 2010

Posted on 2013-06-12
6
649 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 51

Expert Comment

by:Rgonzo1971
ID: 39243666
0
 
LVL 16

Accepted Solution

by:
terencino earned 500 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

752 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