View Single Post
 
Old 09-20-2015, 12:09 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

What you ask is quite straightforward. You need to set up events for adding to the various folders. e.g. Put the following code in the ThisOutlookSession module and then run the macro Application_Startup (this will normally run when you restart Outlook, but you can run it manually).
Then when you move an item into the Newsletters or Officers folders (sub folders of Inbox) it will create a forward message for the moved item.

Because we don't know who you want to send the messages to, the messages are merely displayed so that you can add a recipient and any text, but these can be added in code to olItem and the message sent instead of being displayed.
Code:
Option Explicit
Private WithEvents NewsLetters As Outlook.Items
Private WithEvents Officers As Outlook.Items
Private olItem As Outlook.MailItem

Private Sub Application_Startup()
Dim olApp As Outlook.Application
    Set olApp = Outlook.Application
    Set NewsLetters = GetNS(olApp).GetDefaultFolder(olFolderInbox).folders("NewsLetters").Items
    Set Officers = GetNS(olApp).GetDefaultFolder(olFolderInbox).folders("Officers").Items
lbl_Exit:
    Exit Sub
End Sub

Private Sub Newsletters_ItemAdd(ByVal item As Object)
    On Error GoTo err_Handler
    Set olItem = item.Forward
    olItem.Display
lbl_Exit:
    Exit Sub
err_Handler:
    MsgBox Err.Number & " - " & Err.Description
    GoTo lbl_Exit
End Sub

Private Sub Officers_ItemAdd(ByVal item As Object)
    On Error GoTo err_Handler
    olItem.Display
lbl_Exit:
    Exit Sub
err_Handler:
    MsgBox Err.Number & " - " & Err.Description
    GoTo lbl_Exit
End Sub

Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
    Set GetNS = app.GetNamespace("MAPI")
lbl_Exit:
    Exit Function
End Function
Save the changes at the prompt on leaving Outlook.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote