![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
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? |
Ads |
#2
|
|||
|
|||
![]()
Maybe that item isn't a mail item? Get it as an Object and test for
item.Class to see if it really is an email item. Also, NewMail() is hardly the best event to use, it misses things and only fires at intervals. Use NewMailEx(), which provides a delimited list of EntryID's for every item that's come in since the last time that event fired. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "Swapnil G." Swapnil wrote in message ... 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? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Getting Subject and body information using Application.NewMail eve | Al_21_11[_2_] | Add-ins for Outlook | 3 | January 12th 09 08:42 PM |
outlook newmail event for different version causing problems | kedar_vj via OfficeKB.com | Add-ins for Outlook | 3 | January 16th 07 04:05 PM |
Outlook macro abends but Word macro runs successfully | Jreue | Outlook and VBA | 0 | December 13th 06 11:55 PM |
Call macro stored in Excel workbook from Outlook's macro | Gvaram | Outlook and VBA | 5 | October 4th 06 06:26 AM |
How to fire NewMail&NewMailEx Event? | baryon | Outlook - General Queries | 0 | August 17th 06 04:31 PM |