MSFT Outlook VBA处理新邮件的方法
俺們有兩個郵箱,1個外部的郵箱1(outlook),1個內部郵箱0(lotus notes)。想要outlook郵箱收到新郵件之后判斷一下subject的內容,如果是"kkk:"開頭,則將"kkk:"后面的內容作為to發到lotus notes的郵箱里面去。
測試環境(xp+msft outlook),按alt+F11進入VBA編輯。注意要在工具 -> 宏 -> 安全性中設置為低。部分代碼如下(手抄的,可能有錯哦~~):
option explicit
public WithEvents outApp as Outlook.Application
?
Sub Initialite_handle ()
set outApp = Application
End Sub
?
' 打開OutLook的時候調用,注冊application引用
private sub Application_Startup ()
Initialize_handle
End Sub
'注意函數命名,收到新郵件的時候自動調用
Private sub outApp_NewMailEx (ByVal EntryIDCollection As String)
Dim mai As Object
Dim intInitial As Integer
Dim intFinal As Integer
Dim strEntry As String
Dim intLength As Integer
?
intInitial - 1
intLength = Len(EntryIDCollection)
intFinal = InStr(intInitial, EntryIDCollection, ",")
Do While intFinal <> 0
strEntryID = Stringmid(EntryIDCollection, intInitial, (intFinal - intInitial))
set mai = Application.Session.GetItemFromID(strEntryID)
newmail_proc mai
intInitial = intFinal +1
intFinal = inStr(intInitial, EntryIDCollection, ",")
Loop
strEntryID = String.mid(EntryIDCollection, intInitial, (intLength - intInitial)+1)
set mai = Application.Session.GetItemFromID(strEntryID)
newmail_proc mai
End Sub
?
private sub newmail_proc (ByVal mai As Object)
Dim itm As Object
Dim result As Integer
Dim str_kkk As String
Dim str_subject As String
Dim len_subject As Integer
Dim str_body As String
Dim str_reception As String
?
str_subject = mai.subject
len_subject = Len(str_subject)
?
str_kkk = String.mai(str_subject, 1, 4)
result = String.strComp(str_kkk, "kkk:", vbTextComare)
if result <> 0 then
Else
String_reception = String.mid(str_subject, 5, (len_subject-4)+1)
str_body = mai.body
set Itm = outApp.CreateItem(0)
with Itm
.subject = "new mail from a@a.com"
.to = str_reception
.body = str_body
.send
End With
End if
End Sub
總結
以上是生活随笔為你收集整理的MSFT Outlook VBA处理新邮件的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 解决Adobe PhotoShop用户界
- 下一篇: jq金钱如何加千分位_拼多多如何玩转场景