PDA

View Full Version : [SOLVED:] Print email when moved to a subfolder



Tina
06-29-2017, 09:02 AM
Hi

I have Outlook 2010. I'm trying to write code that will print an email when it is moved into a folder. That bit I have managed, and it works fine. However that is when moving an email into the folder "Worldox" which sits at the same level as Inbox. I can't seem to work out how to code it so that it works when moving mail into a subfolder of "Worldox", eg into "Joey"

The other issue is that the subfolders may be added/deleted/renamed so to future proof the code it would be helpful if it could print when mail is moved into any subfolder of "Worldox" Is that possible?


The code that I have so far is

Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim Ns As Outlook.NameSpace
Set Ns = Application.GetNamespace("MAPI")
Set Items = Ns.GetDefaultFolder(olFolderInbox).Parent.Folders("Worldox").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
Mail.PrintOut
End Sub

I'm not very good with VB so any help would be very much appreciated!

skatonni
06-29-2017, 07:58 PM
You walked from the default inbox to the mailbox to Worldox so keep on walking to Joey.

Set Items = Ns.GetDefaultFolder(olFolderInbox).Parent.Folders("Worldox").Folders("Joey").Items

I believe if you want to listen to new or renamed subfolders of Worldox you will need code for each folder.

Tina
06-30-2017, 08:13 AM
That worked, thank you.

Unfortunately we use Citrix and every time I log off I loose the macro. I know how to change where the macro is saved in Word, can't I can't seem to find how to change it in Outlook. Any ideas?