将Outlook电子邮件另存为文本文件,然后在其上运行脚本吗? [英] Save Outlook Email as text file, and then run a script on it?

查看:118
本文介绍了将Outlook电子邮件另存为文本文件,然后在其上运行脚本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Outlook2007.我没有Windows编程或VBA的经验,因为我的所有背景都是Unix系统.我试图让Outlook将每个收到的电子邮件另存为文本文件,然后运行将解析此文本文件的python脚本.

I'm using Outlook 2007. I have no experience with Windows programming or VBA, as all of my background is on Unix systems. I am attempting to have Outlook save each incoming emails as text file, and then a run a python script which will parse this text file.

我发现了这个问题似乎提供了一些VBA代码来完成第一个任务,但是我不确定如何利用它.我打开了Visual Basic编辑器,但不知道如何从那里继续.我尝试将文本另存为模块,但是当我尝试在Outlook规则中添加运行脚本"时,没有可用的脚本.我在做什么错了?

I found this question which seems to provide some VBA code to accomplish the first task, but I'm not sure how to utilize it. I open the Visual Basic Editor, but have no idea how to proceed from there. I tried saving the text as a module, but when I attempt add "run a script" in an Outlook rule, no scripts are available. What am I doing wrong?

澄清.

推荐答案

我假设您熟悉 some 级别的编码,即使不是在Windows上也是如此.您可能需要在Outlook VBA上进行一些常规的背景阅读;某些资源将是 Microsoft文章这篇文章(来自OutlookCode),等等-大量资源以及演练和示例.

I'm assuming you're familiar with coding at some level, even if not on Windows. You may want to do some general background reading on Outlook VBA; some resources on this would be a Microsoft article, this article from OutlookCode, and so on - there's a ton of resources out there with walkthroughs and examples.

解决您的特定问题:请查看这篇Microsoft KB文章 ,介绍了如何根据规则触发脚本.

Addressing your specific question: take a look at this Microsoft KB article, which describes how to trigger a script from a rule.

打开VBA编辑器后,入门的关键是双击左侧的模块,例如ThisOutlookSession(在"Microsoft Outlook Objects"下). 那应该给您一个编辑器,您可以将代码粘贴到其中.请记住(在上面的MS页中)您的过程必须接受MailItem对象,该对象将是规则掌握的项目,因此您给出的链接示例的前几行内容应更改为:

The key to getting started once you've gotten your VBA editor open is to double-click a module on the left, for example ThisOutlookSession (under 'Microsoft Outlook Objects'). That should give you an editor you can paste code into. Bear in mind that (per the above MS page) your procedure must accept a MailItem object, which will be the item that the rule has in hand, so the linked example you gave would have the first couple of lines changed from:

Sub SaveEmail()
    Dim msg As Outlook.MailItem
    ' assume an email is selected
    Set msg = ActiveExplorer.Selection.Item(1)
    ' save as text
    [...]

...发送至:

Sub SaveEmail(msg As Outlook.MailItem)
    ' save as text
    [...]

从本质上来说,您将被交给一个MailItem,而不必创建它并将其连接到Outlook中的选定项目.

Essentially you're being handed a MailItem rather than having to create it and connect it to the selected item in Outlook.

要实现在文件上运行脚本"的第二项任务,我假设您希望VBA在文件保存后对文件进行更改?在VBA中,这非常简单,您将找到很多示例. 此答案.

To achieve the second task of 'running a script' on the file, I'm assuming that you want your VBA to make changes to the file after it's been saved? This is pretty straightforward in VBA, and you'll find lots of examples for it. One pretty simple outline is in this answer.

基于注释进行以启动外部工具,您可以使用此流行的.或者,您可以在此答案中使用WScript方法.

Edit based on comments: to launch an external tool, you can use either the Shell command if you don't need to wait for it to complete, or you can use one of the many Shell-and-wait implementations floating around, for example this popular one. Or, you can use the WScript approach in this answer.

请注意,您需要

Note that you'll need to ensure Outlook is set to allow macros to run, and you will probably want to sign your code.

这篇关于将Outlook电子邮件另存为文本文件,然后在其上运行脚本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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