Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 140
  • Last Modified:

Trigger a script when mail items are placed into a mail folder

The user is currently moving emails manually (as a manual process) into a mail folder.

We need Outlook to automatically run a script when the emails are placed into that folder.  I saw some posts on .itemadd but need some sample code that will detect when the user moves the emails and then run a script on all emails in that folder.

The script (which we have ready) sends a template reply to all emails in that folder.

We would also like the email to then be moved to a different folder (for archive) once the script is ran per email.

Any ideas on how to set this up?
0
jkanisut
Asked:
jkanisut
1 Solution
 
Rgonzo1971Commented:
HI,

pls try something similar in thisOutlook

Private WithEvents olMyFolderItems As Items

Private Sub Application_Startup()
  Dim objNS As NameSpace
  Set objNS = Application.Session
  ' instantiate objects declared WithEvents
  Set olMyFolderItems = objNS.GetDefaultFolder(olFolderInbox)).Folders("MyFolder").Items
  Set objNS = Nothing
End Sub

Private Sub olMyFolderItems_ItemAdd(ByVal Item As Object)
  MsgBox "You've placed an item in the myFolder Folder
  Set Item = Nothing
End Sub

Open in new window

Regards
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now