This Domain Is For Sell, Contact: admin@mrvsto.com
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 "laoyebin@gmail.com"
        .Body = sBody
        .Subject = sSubject
        .Send
    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?


Hot:

● 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

  One Response to “VBA/OUTLOOK: Newmail event in outlook”

  1. Did you try GetNext instead of GetLast?

 Leave a Reply

(required)

(required)

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=""> <strike> <strong>