Solved

Macros in Outlook 2010

Posted on 2013-06-12
6
561 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 48

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This collection of functions covers all the normal rounding methods of just about any numeric value.
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now