Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Macros in Outlook 2010

Posted on 2013-06-12
6
Medium Priority
?
709 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 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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…
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…

927 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