?
Solved

Autorun MACRO on Send & Recieve...

Posted on 2004-08-27
8
Medium Priority
?
607 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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.

Question has a verified solution.

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

Changing a few Outlook Options can help keep you organized!
Today as you open your Outlook, you witness an error message: “Outlook is using an old copy of your Outlook Data File…”. Probably, Outlook is accessing an old OST file.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

850 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