Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 09-20-2015, 12:09 AM
gmayor's Avatar
gmayor gmayor is offline VBA rule to forward messages from specific folder and forward Windows 7 64bit VBA rule to forward messages from specific folder and forward Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
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 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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA rule to forward messages from specific folder and forward Rule to move sent messages to a specific folder LouisOscar Outlook 1 08-17-2011 05:42 AM
Auto Forward Emails - Specific Time Periods Only Dav Outlook 0 06-22-2011 12:03 PM
VBA rule to forward messages from specific folder and forward Create Rule to forward message to mobile# JoyConner Outlook 1 04-21-2011 05:44 PM
Forward Unread Messages after X Minutes? BamaBrad Outlook 2 03-13-2011 07:57 AM
Code to auto-forward weekend messages Whang Outlook 0 06-16-2010 02:18 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:12 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft