Discussion:
run macro when mail received
(too old to reply)
jason
2010-02-09 15:29:40 UTC
Permalink
thank in advance.

i am using the below code referenced directly from msdn (http://
msdn.microsoft.com/en-us/library/aa171307(office.11).aspx)

but it does not seem to be working. I created and placed in a class
file as directed.

any help on (if there exists) a simpler way to code this or a way to
get this work would be a great help.


thank you!
-------

Public WithEvents myOlApp As Outlook.Application

Sub Initialize_handler()
Set myOlApp = CreateObject("Outlook.Application")
End Sub

Private Sub myOlApp_NewMail()
Dim myExplorers As Outlook.Explorers
Dim myFolder As Outlook.MAPIFolder
Dim x As Integer
Set myExplorers = myOlApp.Explorers
Set myFolder =
myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
If myExplorers.Count <> 0 Then
For x = 1 To myExplorers.Count
On Error GoTo skipif
If myExplorers.Item(x).CurrentFolder.Name = "Inbox" Then
myExplorers.Item(x).Display
myExplorers.Item(x).Activate
Exit Sub
End If
skipif:
Next x
End If
On Error GoTo 0
myFolder.Display
End Sub
Sue Mosher [MVP]
2010-02-09 15:39:30 UTC
Permalink
Coding the NewMail is the least useful way to work with incoming messages.
See http://www.outlookcode.com/article.aspx?id=62 for better approaches. If
you need additional assistance, please state your Outlook version and
explain what you're trying to accomplish with your code.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Post by jason
thank in advance.
i am using the below code referenced directly from msdn (http://
msdn.microsoft.com/en-us/library/aa171307(office.11).aspx)
but it does not seem to be working. I created and placed in a class
file as directed.
any help on (if there exists) a simpler way to code this or a way to
get this work would be a great help.
thank you!
-------
Public WithEvents myOlApp As Outlook.Application
Sub Initialize_handler()
Set myOlApp = CreateObject("Outlook.Application")
End Sub
Private Sub myOlApp_NewMail()
Dim myExplorers As Outlook.Explorers
Dim myFolder As Outlook.MAPIFolder
Dim x As Integer
Set myExplorers = myOlApp.Explorers
Set myFolder =
myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
If myExplorers.Count <> 0 Then
For x = 1 To myExplorers.Count
On Error GoTo skipif
If myExplorers.Item(x).CurrentFolder.Name = "Inbox" Then
myExplorers.Item(x).Display
myExplorers.Item(x).Activate
Exit Sub
End If
Next x
End If
On Error GoTo 0
myFolder.Display
End Sub
jason
2010-02-09 16:23:16 UTC
Permalink
Post by Sue Mosher [MVP]
Coding the NewMail is the least useful way to work with incoming messages.
Seehttp://www.outlookcode.com/article.aspx?id=62for better approaches. If
you need additional assistance, please state your Outlook version and
explain what you're trying to accomplish with your code.
--
Sue Mosher, Outlook MVP
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54
Post by jason
thank in advance.
i am using the below code referenced directly from msdn (http://
msdn.microsoft.com/en-us/library/aa171307(office.11).aspx)
but it does not seem to be working. I created and placed in a class
file as directed.
any help on (if there exists) a simpler way to code this or a way to
get this work would be a great help.
thank you!
-------
Public WithEvents myOlApp As Outlook.Application
Sub Initialize_handler()
   Set myOlApp = CreateObject("Outlook.Application")
End Sub
Private Sub myOlApp_NewMail()
   Dim myExplorers As Outlook.Explorers
   Dim myFolder As Outlook.MAPIFolder
   Dim x As Integer
   Set myExplorers = myOlApp.Explorers
   Set myFolder =
myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
   If myExplorers.Count <> 0 Then
       For x = 1 To myExplorers.Count
           On Error GoTo skipif
           If myExplorers.Item(x).CurrentFolder.Name = "Inbox" Then
               myExplorers.Item(x).Display
               myExplorers.Item(x).Activate
               Exit Sub
           End If
       Next x
    End If
    On Error GoTo 0
    myFolder.Display
End Sub- Hide quoted text -
- Show quoted text -
link was large help.

was able to integrate with my code. it is a conditional move based off
certain criteria.

thanks

Loading...