Outlook 2016 - “选择脚本"规则向导中的窗口是空白的 [英] Outlook 2016 - "select script" window in Rules Wizard is blank

查看:96
本文介绍了Outlook 2016 - “选择脚本"规则向导中的窗口是空白的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行以下宏将附件保存到我计算机上的文件夹中:

I am trying to run the following Macro to save attachments into a folder on my computer:

Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)

    Dim oAttachment As Outlook.Attachment
    Dim sSaveFolder As String
    sSaveFolder = "R:\ConfigAssettManag\Performance\Let's see if this works"

    For Each oAttachment In MItem.Attachments
        oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
        Next

End Sub

由于某种原因,我无法将宏添加到 Outlook 中的规则.我读了 here 我需要让它返回 Outlook.MailItem,我的代码已经这样做了,所以我不知道为什么宏仍然没有显示up.Outlook 规则未显示我的宏

I cannot add the macro to the rule in Outlook for some reason. I read here that I needed to have it return an Outlook.MailItem, and my code already does that, so I do not know why the macro is still not showing up.Outlook Rule not showing my Macro

推荐答案

我认为答案有些晦涩,例如您必须像这样声明 ByRef:

I think the answer is something obscure like you must declare ByRef like this:

Public Sub SaveAttachmentsToDisk(ByRef MItem As Outlook.MailItem)

让我为您节省大量时间.您会发现使用 Outlook 规则运行脚本行不通.相反,您将希望在新邮件进入的实际事件上运行您的代码.这将更改您的代码的优先级并使您远离 Outlook 规则中的所有疯狂错误.稍后谢谢我.

Let me save you a whole bunch of time. You are going to find that using an Outlook rule to run your script doesn't work out. Instead, you will want to run your code on the actual event of a new mail item coming in. This will change the priority of your code and get you away from all the crazy bugs in Outlook rules. Thank me later.

将此代码放入您的ThisOutlookSession"对象中.它只能从那里工作.

Put this code in your "ThisOutlookSession" Object. It only works from there.

Option Explicit
Private WithEvents inboxItems As Outlook.Items

' Set up the listener on the Inbox
Private Sub Application_Startup()
    Dim outlookApp As Outlook.Application
    Dim objectNS As Outlook.NameSpace

    Set outlookApp = Outlook.Application
    Set objectNS = outlookApp.GetNamespace("MAPI")
    Set inboxItems = objectNS.GetDefaultFolder(olFolderInbox).Items
End Sub

' Send new mail to the attachment processor
Private Sub inboxItems_ItemAdd(ByVal Item As Object)
    If TypeName(Item) = "MailItem" Then
        Dim EMail As Outlook.MailItem
        Set EMail = Item
        Debug.Print "Incoming Data."
        SaveAttachmentsToDisk EMail
        Set EMail = Nothing
    End If
End Sub

为了保存文件,试试这个:

For your saving the file, try this:

Dim fullPath As String
fullPath = sSaveFolder & oAttachment.FileName
oAttachment.SaveAsFile fullPath 

然后在 fullPath 行上放置一个中断并在运行时检查该字符串的实际内容.这将帮助您了解文件的实际去向.

Then put a break on the fullPath line and inspect the actual contents of that string during run-time. This will help you see where the files are actually going.

这篇关于Outlook 2016 - “选择脚本"规则向导中的窗口是空白的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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