Solved

Macros in Outlook 2010

Posted on 2013-06-12
6
603 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
6 Comments
 
LVL 49

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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

I wanted to share this with fellow Experts, who might not know. How often have you wanted to learn something, only to be set back by either restrictions imposed on "trial" or "evaluation" software?  How often have you had to rebuild a home networ…
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Viewers will learn the different options available in the Backstage view in Excel 2013.
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…

770 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