识别触发在规则中运行脚本代码的项目 [英] Identify item that triggered run a script code in a rule

查看:55
本文介绍了识别触发在规则中运行脚本代码的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将收到的任何电子邮件的内容自动导出到文本文件中.如果该文本文件中已有文本,则新文本应覆盖它.

I want to export the contents of any email that is received to a text file automatically. If there is text already in that text file, then the new text should overwrite it.

可以制定规则以在收到电子邮件时运行此脚本.

A rule can be made to run this script when an email is received.

例如:
我收到一封电子邮件,上面写着生日快乐".

For example:
I receive an email that says "Happy Birthday".

文本生日快乐"应保存到incomingEmail.txt"

The text "Happy Birthday" should be saved to "incomingEmail.txt"

Sub extractDataAsString(item As Outlook.MailItem)
    Dim olItem As Outlook.MailItem
    Dim sText As String

    Set olItem = ActiveExplorer.Selection.item(1)
    sText = olItem.Body

    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")

    Dim Fileout As Object
    Set Fileout = fso.CreateTextFile("K:\Project\Python\incomingEmail.txt", True, True)
    Fileout.Write sText
    Fileout.Close

End Sub

上面的代码将当前选定的电子邮件正文导出到文本文件.我想将新电子邮件的正文导出到文本文件中.

The code above exports the currently selected e-mail's body to the text file. I want to export the body of the new e-mail to the text file.

我认为这是因为这条线:

I think this is because of the line:

Set olItem = ActiveExplorer.Selection.item(1)

但是,我找不到如何选择最新的电子邮件.

However, I can't find how to select the latest e-mail.

推荐答案

触发运行脚本代码的项目传递给代码.不用再找了.

The item that triggers run a script code is passed to the code. There is no need to find it again.

Sub RunAScript_code(item As Outlook.MailItem)

    MsgBox "The item that triggered this code is: " & item.subject

End Sub

这篇关于识别触发在规则中运行脚本代码的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆