Solved

Autorun MACRO on Send & Recieve...

Posted on 2004-08-27
8
555 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Outlook Free & Paid Tools
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
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 …

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now