Thread: [Solved] Help to create a rule
View Single Post
 
Old 06-15-2016, 08:15 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The red text suggests that you don't have the appropriate sounds dll installed, so delete the previous macros and use the following simpler version instead. The yellow line may reflect the above error, or it could indicate that the Maria folder is not a sub folder of the default inbox. If that is the case I would need to know your Outlook folder structure in order to suggest changes.

Code:
Option Explicit
Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Dim olApp As Outlook.Application
    Set olApp = Outlook.Application
    Set Items = GetNS(olApp).GetDefaultFolder(olFolderInbox).folders("Maria Alencar").Items
End Sub

Private Sub Items_ItemAdd(ByVal item As Object)
    On Error GoTo ErrorHandler
    Beep
    MsgBox "There's a new item in Maria's folder."
ProgramExit:
    Exit Sub
ErrorHandler:
    Beep
    MsgBox Err.Number & " - " & Err.Description
    Resume ProgramExit
End Sub

Private Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
    Set GetNS = app.GetNamespace("MAPI")
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote