Hi,
I'm a novice to VBA, however I'm working on a button to provide an option to send and print emails with a click of the button. I want all of the header information included in the printouts (such as the date it was sent), so I can only print the emails after they have actually been sent (i.e. moved from the outbox to the sent items folder).
I set up a macro and added a button to the ribbon to assign a "print" category to all outgoing emails when I click the button. The code is as follows:
I need code to process any items added to the Sent Items folder to look for the "Print" category, print the email if the category is present.
I tried using the following code, which I found on the web, and modified for my needs, but it didn't work:
I tried entering it as a module, but after some digging I found that it needed to be entered as a class module. So I entered it as a class module, however it's still not working. Can someone help? I'm using Office 2010 64-bit.
After I get that part working, I'd like to add another line of code to remove the "Print" category from the printed email, just to clean up the process a little bit.
Thanks,
Mark
I'm a novice to VBA, however I'm working on a button to provide an option to send and print emails with a click of the button. I want all of the header information included in the printouts (such as the date it was sent), so I can only print the emails after they have actually been sent (i.e. moved from the outbox to the sent items folder).
I set up a macro and added a button to the ribbon to assign a "print" category to all outgoing emails when I click the button. The code is as follows:
Code:
Sub SendPrint()
Dim obj
Dim oCategory As Outlook.Category
Set obj = ActiveInspector.CurrentItem
Set objOL = CreateObject("Outlook.Application")
If Not objOL.ActiveInspector Is Nothing Then
Set objItem = objOL.ActiveInspector.CurrentItem
objItem.Categories = "print"
End If
obj.Send
End Sub
I need code to process any items added to the Sent Items folder to look for the "Print" category, print the email if the category is present.
I tried using the following code, which I found on the web, and modified for my needs, but it didn't work:
Code:
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim Ns As Outlook.NameSpace
Set Ns = Application.GetNamespace("MAPI")
Set Items = Ns.GetDefaultFolder(olFolderSentItems).Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
PrintNewItem Item
End If
End Sub
Private Sub PrintNewItem(Mail As Outlook.MailItem)
On Error Resume Next
If MailItem.Categories Is "Print" Then
Mail.PrintOut
End If
End Sub
I tried entering it as a module, but after some digging I found that it needed to be entered as a class module. So I entered it as a class module, however it's still not working. Can someone help? I'm using Office 2010 64-bit.
After I get that part working, I'd like to add another line of code to remove the "Print" category from the printed email, just to clean up the process a little bit.
Thanks,
Mark