This Domain Is For Sell, Contact:
Apr 252010

I wanted to forward a mail to somebody when I’m receiving a mail, so I used this VBA code to do it.

Private Sub Application_NewMail()
    Dim myItem, sBody$, sSubject$
    Set myItem = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items.GetLast
    sBody = myItem.Body
    sSubject = myItem.Subject
    With myItem.Forward
        .Recipients.Add ""
        .Body = sBody
        .Subject = sSubject
    End With
End Sub

It should be correct in theory. But, I find a problem, it isn’t the lastest mail, it’s the second one.
I’m confused, is it a bug?


● Use Microsoft Office 2007 like a Pro!
● Excel Expert User-Your One Stop Solution In Mastering Microsoft Excel
● 101 Secrets of a Microsoft Excel Addict
● Excel VBA Made Easy
● Doc2Txt
● Create Your Own Programming Language

Author:laoyebin (Paladin.lao)
From:VSTO&Excel Space of Paladin Lao
Post :VBA/OUTLOOK: Newmail event in outlook

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>