button to send and print emails

Status
Not open for further replies.

mdarnold

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Yes, I did, but got side tracked with end-of-summer stuff. :( It is a limitation when using code to print. Email doesn't have pages so the length is determined by the printer driver but vba hooks in to the process after that point. It can count the pages as it prints but not calculate the total.

Thanks for your reply. Too bad it works that way.

Do you know of a way to set the Print Style using vba? I'm wondering if I could set up another print style that doesn't refer to the total pages for when I print using code, and have the code use that print style automatically.
 

Forum Admin

Senior Member
The problem is the print stuff is not exposed in the object model and you need to use the shell. I believe the settings are in the registry, so you could change it using code.

There is a program called regshot that can read the registry before you make a change then read it after and compare - that will get the key and values that need changed.
 

mdarnold

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
The problem is the print stuff is not exposed in the object model and you need to use the shell. I believe the settings are in the registry, so you could change it using code.

There is a program called regshot that can read the registry before you make a change then read it after and compare - that will get the key and values that need changed.

Took me a little time to look into this, but I found the key and values.

HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Printing\PrintTypesDefault\100: 0x0000000C

HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Printing\PrintTypesDefault\100: 0x0000000D

Is there an easy way to switch the value of the registry key to 0x0000000D before the Item.PrintOut command and back to 0x0000000C afterwards?

Code:
Sub SendPrint() 
 
Dim obj 
 
Dim oCategory As Outlook.Category 
 
Set obj = ActiveInspector.CurrentItem 
 
obj.Categories = "Print" 
 
obj.Send 
 
End Sub 
 
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
   If TypeOf Item Is Outlook.MailItem And Item.Categories = "Print" Then
       Item.PrintOut
   End If 
 
End Sub
 

mdarnold

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
I think this might work, but I can't test it at home; I'll check tomorrow at work. Can you let me know if you see anything obviously wrong with it?

Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  If TypeOf Item Is Outlook.MailItem And Item.Categories = "Print" Then
       Set myWS = CreateObject("WScript.Shell")
       myWS.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Printing\PrintTypesDefault\100", "0x0000000D", REG_DWORD
       Item.PrintOut
       myWS.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Printing\PrintTypesDefault\100", "0x0000000C", REG_DWORD
   End If 
 
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
It looks good to me - it's pretty much what I would have suggested. Except its erroring on the regwrite lines (I put the set line + one regwrite line in a macro to test it.) . The REG_DWORD part is the problem, it works if it remove it (but saves the wrong kind of key.)
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I can't believe I didn't notice it sooner - you don't use 0x0000000D, you use the number behind it, in the brackets.

myWS.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Printing\PrintTypesDefault\100", "13", "REG_DWORD"
 

mdarnold

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
I can't believe I didn't notice it sooner - you don't use 0x0000000D, you use the number behind it, in the brackets.

myWS.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Printing\PrintTypesDefault\100", "13", "REG_DWORD"

Thanks! I also had to define myWS (add Dim myWS As Object), but after that it worked like a charm.

Thanks so much for your help!
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Send and Receive Button - only check default account? Using Outlook 1
A custom send button Outlook VBA and Custom Forms 3
H Preventing the Send button from being clicked on an Outlook Form Outlook VBA and Custom Forms 1
S Create a custom "Send" Button Outlook VBA and Custom Forms 3
Commodore Button for Send/Received for a specific account Using Outlook 4
Commodore Button for a specific Send/Receive Group Using Outlook 1
M Programatically click the Send button. Outlook VBA and Custom Forms 5
N modify New mesage SEND button Outlook VBA and Custom Forms 1
B Customized Send button Outlook VBA and Custom Forms 5
G Outlook 2007 Meeting Item Send Button Outlook VBA and Custom Forms 10
D Button beside send, but not beside reply Outlook VBA and Custom Forms 2
J How to hide/disable send button in Outlook 2007 Outlook VBA and Custom Forms 1
J How to hide/disable send button in Outlook 2007 Outlook VBA and Custom Forms 2
J How to hide/disable send button in Outlook 2007 Outlook VBA and Custom Forms 1
A adding a custom send button? Outlook VBA and Custom Forms 1
bdsermons Outlook 365 command button in outlook form Outlook VBA and Custom Forms 5
J "Contact" button in Journal entry Using Outlook 1
O Outlook 2010 Add delete button to the side of the message list Using Outlook 1
I Button PDF in Outlook Contact custom form Outlook VBA and Custom Forms 1
D Outlook 2013 Macros only run in VB editor, not in drop down or button Outlook VBA and Custom Forms 14
N contact list seen in Contact folder but knot in Address book or when 'TO' button is clicked in new email Using Outlook 0
witzker HowTo start a macro with an Button in OL contact form Outlook VBA and Custom Forms 12
R Follow up button doesn't working neither the reminders in BCM BCM (Business Contact Manager) 0
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
K Disabling import/export button to restrict PST creation Using Outlook 3
N Which Button Was Clicked on the Ribbonbar Menu Outlook VBA and Custom Forms 2
E Can't accept or decline task (no button appears) Using Outlook 2
M VbScript for Command Button on Contacts Custom Form Using Outlook 1
Q Prompt button to auto turn on Out of Office Outlook VBA and Custom Forms 3
C iCloud Setting missing Outlook tab and Outlook missing the iCloud refresh button Using Outlook 4
witzker Outlook 2010 Insert Date & Time at the button of an OL contactform in red Using Outlook 2
S How to set up button in ribbon for individual Quick Steps Using Outlook 1
C Custom Outlook Form - Populate Information from Radio Button / Check Box Using Outlook 0
J Command Button to stamp a date and time in a textbox in Outlook 2016 Outlook VBA and Custom Forms 3
A ScanPST finding errors but no Repair button Using Outlook 2
N Creating a button or link to a form in the Organizational Forms Library Outlook VBA and Custom Forms 3
J Execute Add-In Button from VBA Outlook 2016 Outlook VBA and Custom Forms 1
D Command Button code will not execute. Any suggestions Please. Outlook VBA and Custom Forms 2
S Reminder Dialog Open Button Using Outlook 2
Wayne Dardis Calling Ribbon Button in Outlook 2016 Outlook VBA and Custom Forms 6
Tanja Östrand Outlook 2016 - Create Macro button to add text in Subject Outlook VBA and Custom Forms 1
R Categorize Button in Quick Access Toolbar Disappears on New Email Using Outlook 1
S Problem running Command button code Outlook VBA and Custom Forms 2
E Button to change subject Outlook VBA and Custom Forms 1
S Shortcut/button to a Calendar Group Using Outlook 0
soadfan Enable all rules from toolbar button? Outlook VBA and Custom Forms 3
I Creating meeting invite with disabled tentative button Outlook VBA and Custom Forms 5
Diane Poremsky Contacts are missing when you click the To button Using Outlook 0
T Unable to 'Upload a file' using popup 'Browse' button Using Outlook 0
makinmyway ScanPST.exe Missing Repair Button Using Outlook 15

Similar threads

Top