S
Swapnil G.
I have a Outlook macro that checks for perticular words on receiving new
mail. If that word is found, it desplays a msg in msgbox. see below the code;
Private Sub Application_NewMail()
Dim oNS As NameSpace
Dim oFolder As MAPIFolder
Dim oItem As Object
Dim oNewMail As MailItem
Dim var As Variant
Set oNS = GetNamespace("MAPI")
Set oFolder = oNS.GetDefaultFolder(olFolderInbox)
Set oNewMail = oFolder.Items.GetLast
With oNewMail
'MsgBox .Subject & " " & .SenderName
For Each var In Array("Good Work", "Great Job", "Excellent", "Great
Work", "Keep it up", "Very Good")
If InStr(1, .Body, var, vbTextCompare) <> 0 Then
MsgBox "Congrats! " & .ReceivedByName & " Your work just got
appriciated by " & .SenderName, vbOKOnly
MsgBox "Go ahead and record it in CED. ", vbOKOnly
End If
Next
End With
End Sub
This code work fine. However I am getting a weird problem. When I lock and
then unlock my PC, an error msg pops up 'Run-time error 13: Type mismatch'
and on clicking 'debug' button it points out to line " Set oNewMail =
oFolder.Items.GetLast" in above code. Even if I click 'cancel' button, it
opens VBA editior.
Can somebody help me to get rid of this bug please?
mail. If that word is found, it desplays a msg in msgbox. see below the code;
Private Sub Application_NewMail()
Dim oNS As NameSpace
Dim oFolder As MAPIFolder
Dim oItem As Object
Dim oNewMail As MailItem
Dim var As Variant
Set oNS = GetNamespace("MAPI")
Set oFolder = oNS.GetDefaultFolder(olFolderInbox)
Set oNewMail = oFolder.Items.GetLast
With oNewMail
'MsgBox .Subject & " " & .SenderName
For Each var In Array("Good Work", "Great Job", "Excellent", "Great
Work", "Keep it up", "Very Good")
If InStr(1, .Body, var, vbTextCompare) <> 0 Then
MsgBox "Congrats! " & .ReceivedByName & " Your work just got
appriciated by " & .SenderName, vbOKOnly
MsgBox "Go ahead and record it in CED. ", vbOKOnly
End If
Next
End With
End Sub
This code work fine. However I am getting a weird problem. When I lock and
then unlock my PC, an error msg pops up 'Run-time error 13: Type mismatch'
and on clicking 'debug' button it points out to line " Set oNewMail =
oFolder.Items.GetLast" in above code. Even if I click 'cancel' button, it
opens VBA editior.
Can somebody help me to get rid of this bug please?