Solved

Autorun MACRO on Send & Recieve...

Posted on 2004-08-27
8
581 Views
Last Modified: 2008-03-10
Is there a way to trigger a MACRO to run automaticaly after every send & recieve?
0
Comment
Question by:will_scarlet7
  • 5
  • 3
8 Comments
 
LVL 13

Expert Comment

by:stefri
ID: 11919577
Private WithEvents olInboxItems As Items
Dim objNS As NameSpace


Private Sub Application_Startup()
  Set objNS = Application.GetNamespace("MAPI")
  Set olInboxItems = objNS.GetDefaultFolder(olFolderOutbox).Items
End Sub

Private Sub Application_Quit()
  Set objNS = Nothing
End Sub

' sending mails function
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
' your code
End Sub

' receiving mails function: items aded to inbox items collection
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)

  On Error Resume Next

  If Item.Class = olMail Then
      ' your code
  End If
 
End Sub
stefri
0
 
LVL 15

Author Comment

by:will_scarlet7
ID: 11919614
ThanX Stefri! Looks good in theory. I'll test it out later today and let you know how it goes. Do you know if I can set this to a folder other that inbox as well?
0
 
LVL 13

Accepted Solution

by:
stefri earned 500 total points
ID: 11919667
I noticed an error: use olFolderInbox instead of olFolderOutbox

Private WithEvents olIncomingItems As Items
Dim objNS As NameSpace
  Dim objFld As MAPIFolder
  Dim objInbox As MAPIFolder

Private Sub Application_Startup()
  Set objNS = Application.GetNamespace("MAPI")
  Set objInbox = objNS.GetDefaultFolder(olFolderInbox) ' get inbox folder

  'Set objFld = objInbox.Folders("your folder") ' if folder is child of Inbox

  'Set objFld = objInbox.Parent.Folders("your folder") ' if folder is at the same level of Inbox

  Set olIncomingItems = objFld.Items

End Sub

Private Sub Application_Quit()
  Set objNS = Nothing
  Set objFld = Nothing
  Set objInbox = Nothing
End Sub

' sending mails function
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
' your code
End Sub

' receiving mails function: items aded to objFld items collection
Private Sub olIncomingItems_ItemAdd(ByVal Item As Object)
  On Error Resume Next

  If Item.Class = olMail Then
     ' your code
  End If
 
End Sub
usually mails are received in Inbox (not sure if it will work if you have setup a rule to move incoming mails not another folder)
Uncomment one of the ' Set ObjFld lines according to your needs
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 15

Author Comment

by:will_scarlet7
ID: 11919706
I super appreciate it! I'll let you know how it goes when I test it later.

ThanX!

Sam
0
 
LVL 15

Author Comment

by:will_scarlet7
ID: 11994798
ThanX for your help! It worked beautifully.

God bless!

Sam
0
 
LVL 15

Author Comment

by:will_scarlet7
ID: 14466599
Are you still partricipating in the EE Stefri?
0
 
LVL 13

Expert Comment

by:stefri
ID: 14478898
not really....
Am I missing you?
I switch job position 6 months ago (still the same company) from Messaging system to HR system....
I was accustomed to appliance failures, not to people failure: HR network has bottleneck, and looks like a NFS server: not responding...still trying....

That is why I had no time to come to EE and participate to threads
I shall try to hook up again

Stefri
0
 
LVL 15

Author Comment

by:will_scarlet7
ID: 14479054
Hi,
If you have the time and are still interested in Outlook programming I would appreciate any thoughts you have on the following question:
http://www.experts-exchange.com/Applications/MS_Office/Outlook/Q_21497211.html

From when I first started learning Outlook events and automation you were the one who helped me the most, so I value any insight you might have.

Sam
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question