Solved

Autorun MACRO on Send & Recieve...

Posted on 2004-08-27
8
588 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

To Patch or not to Patch? That is the question!

Don't get caught out like thousands of others around the world in the recent Ransomware Fiasco!
Discuss..
- Why it's not a good idea to wait before Patching
- Sensible approaches to Patching discussed
- Add your feedback, comments and suggestions

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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 …

739 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