问题描述
我的问题与此线程和这一个一个>.我认为我的问题是将这两个问题结合在一起.
My problem is very similar to this thread and this one. I think my issue is to combine these two questions.
我正在跑步:
- 操作系统:Windows 7 Enterprise Professional
- Outlook 2010
- VBA 7.0版
通过阅读这两个问题以及Microsoft和其他地方的其他一些页面,我能够打开VB编辑器并将其粘贴到此简单代码中:
By reading these two questions as well as some other pages from Microsoft and elsewhere, I was able to open the VB editor and paste into it, this simple code:
Sub SaveEmail(msg As Outlook.MailItem)
' save as text
msg.SaveAs "C:\Users\mel\mailsave\email.txt" & Format(Now, "YYYYMMDDHHMMSS"), _
olTXT
End Sub
- msg.SaveAs行的格式"部分是否要为与我的规则匹配的每封电子邮件保存一个唯一的文本文件?
- 如何运行此宏进行测试,如果成功,如何重复运行?
我尝试转到运行菜单并选择运行子/用户窗体"项,但是下一个对话框询问要运行的内容,并且未填充可用于运行的宏的列表.单击保存"图标,但未做任何更改.
I tried going to the run menu and selecting run "sub/user form" item but the next dialog box is asking what to run and does not populate a list of macros available for running. Clicked on "save" icon but nothing changed.
推荐答案
指定具有该签名(Sub method (var As Outlook.MailItem)
)的方法可让您在创建邮箱规则时使用该方法.据我了解您的问题,您已经超出了这一点.
Specifying a method with that signature (Sub method (var As Outlook.MailItem)
) allows you to use the method when creating a mailbox rule. As far as I understand your question, you're beyond that point.
问题1
代码的格式部分最多只能每秒保存一个唯一文件.您要将当前日期和时间附加到文件中.但是,您的主要问题不是时间戳,而是文件格式.您应该在文件扩展名之前应用时间戳,例如
The format portion of your code is only going to save a unique file at most once per second. You're appending the current date and time to the file. Your main problem, however, is not the timestamp, but the file format. You should apply the timestamp before the file extension, e.g.
msg.SaveAs "C:\Users\mel\mailsave\email" & Format(Now, "YYYYMMDDHHMMSS") & ".txt", olTXT
问题2
如果将宏添加到规则中,则在匹配规则时将运行该宏.可以通过创建抓取当前所选邮件的方法来测试该宏,例如
If you add the macro to a rule, it will be run when the rule is matched. The macro can be tested by creating a method that grabs the currently selected mail, e.g.
Sub TestSaveEmail()
Call SaveEmail(ActiveExplorer.Selection(1))
End Sub
然后可以通过在方法中设置光标并按F5来运行此宏.
This macro can then be run by setting the cursor within the method and pressing F5.
还可以通过自定义功能区并添加宏按钮将宏添加到Outlook用户界面.有关自定义功能区的帮助,请参阅以下文章:
The macro can also be added to the Outlook user interface by customizing the ribbon and adding a macro button. For help on customizing the ribbon, refer to the following article:
这篇关于用于将电子邮件另存为文本文件的宏,将在规则中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!