Solved

Autorun MACRO on Send & Recieve...

Posted on 2004-08-27
8
575 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IT Desktop Support 11 74
Issue with using GPO to install Mimecast in Outlook. 6 35
Windows 7 Professional 6 61
OUTLOOK NOT receiving email from YAHOO - Error  0x80042110 7 125
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…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

810 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