Outlook规则将电子邮件保存到文本 [英] Outlook Rule Save email to text
问题描述
使用脚本将电子邮件的正文自动导出到文本文件中,我遇到麻烦。
我已经管理了一个脚本,将文本保存到一个宏上的文件,但这不符合我所需要的规则。
I'm having trouble with automatically exporting the body of an email into a text file using a script. I've managed a script that will save the text into a file on a macro but that won't work on a rule which is what I need.
我目前的代码如下:
Sub SaveAsTXT()
Dim myItem As Outlook.Inspector
Dim objItem As Object
Dim myFolder As Folder
Set myItem = Application.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set myNamespace = Application.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set objItem = myItem.CurrentItem
strname = objItem.Subject
strdate = Format(objItem.ReceivedTime, " yyyy mm dd")
objItem.SaveAs "c:\users\philip\documents\" & strname & strdate & ".txt", olTXT
End If
End Sub
抱歉,如果看起来有点凌乱,我已经编辑了无数次尝试让它工作。
Apologies if it looks a bit messy, I've edited it countless times trying to get it to work.
这是正确运行的代码,当我在打开的电子邮件并将其作为宏运行,但是作为规则运行时无法正常运行
我已尝试修改为 Sub SaveAsTXT(Item as Outlook.Mailitem)
但这似乎也不起作用
That's the code that will correctly run when I'm in the open email and run it as a macro but it won't work correctly when run as a rule
I have tried amending to Sub SaveAsTXT(Item as Outlook.Mailitem)
but this also doesn't seem to work
所以基本上问题是如何确保代码将选择电子邮件(这将始终被称为Rotas没有引号)当它作为一个规则运行时
So basically the question is how to I ensure the code will select the email (which will always be entitled "Rotas" without quotes) when it is run as a rule?
信息:使用office 2010,我不是一个很好的编码器开始。
Info: Using office 2010 and I'm not a very good coder to start with.
推荐答案
其实我设法自己解决了。
Actually I managed to sort it out myself.
我没有将项目视为Outlook.Mailitem
元素实际上是由规则。所以我应用项目
作为对象,而不是 objItem
I didn't consider that the item as Outlook.Mailitem
element was actually the thing that was selected by the rule. So I applied item
as the object rather than objItem
查找下面的成功(和清理)代码:
Find the successful (and cleaned up) code below:
Sub SaveAsTXT(myMail As Outlook.MailItem)
Dim objItem As Object
Dim myFolder As Folder
If Not TypeName(myitem) = "Nothing" Then
If myMail.Subject = "Rotas" Then
strname = myMail.Subject
strdate = Format(myMail.ReceivedTime, " yyyy mm dd")
myMail.SaveAs "c:\users\philip\documents\" & strname & ".txt", olTXT
End If
End If
End Sub
这篇关于Outlook规则将电子邮件保存到文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!