How to reference the mail which triggered the outlook macro?

老子叫甜甜 提交于 2019-12-04 20:43:05

Two steps to skip checking the whole Inbox until a match. Keep yours just in case you need to run it manually for the first matching item.

1) Add code below (altered to use cscript.exe):

Sub TestSuiteInitialilzer_Rules(ByRef oMail As MailItem)
    Const FileName = "C:\Email Attachments\"
    For Each Atmt In oMail.Attachments
        'Download the attachment
        Atmt.SaveAsFile FileName & Atmt.Filename
    Next Atmt
    ' Move the Mail to objDestFolder
    oMail.Move objDestFolder
    'launchQTP = "C:\Unlock.vbs"
    launchQTP = "cscript.exe //nologo C:\Unlock.vbs"
    Set objShell = CreateObject("WScript.Shell")
    'QTP will be launched with the neccassary configurations through the vb script
    objShell.Run launchQTP
    Set objShell = Nothing
End Sub

2) Add Outlook Rule (Apply rule on messages I receive) on top of your existing one. Better to turn off your existing one.

You just need to define a VBA macro sub which accepts a MailItem as a parameter. The source object will be passed to the sub and you don't need to search it in the Inbox folder. For example:

Public Sub Text(mail as Outlook.MailItem)
    ' do something with the mail object
End Sub

You can access attachments using the Attachments property of the MailItem class. The Move method allows to move the item to another folder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!