我在“运行脚本"选择框中看不到我的 VBA 宏 [英] I cannot see my VBA macro in 'run a script' selection box

查看:80
本文介绍了我在“运行脚本"选择框中看不到我的 VBA 宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 VBA 社区之一复制了我的 oulook VBE 中的以下代码,并根据需要对其进行了修改.我可以使用 F5 和 F8 运行它.现在,每当我在文件夹 1 中收到电子邮件时,我都想运行此宏.我尝试设置规则,但看不到运行脚本"选择框中列出的宏.我已经检查过了

I copied the following code in my oulook VBE, from one of the VBA communities and amended it as per my need. I can run it using F5 and F8. Now I would like to run this macro whenever I receive an email in folder1. I tried setting up a rule but I cannot see the macro listed in the 'run a script' selection box. I have already checked that

  1. 宏安全设置正确
  2. 宏在一个模块中而不是在一个类中

你能告诉我设置中出了什么问题吗.

can you please tell me what is going wrong in the setting.

Public Sub SaveAttachments()

    Dim myOlapp As Outlook.Application
    Dim myNameSpace As Outlook.NameSpace
    Dim myFolder As Outlook.MAPIFolder
    Dim yourFolder As Outlook.MAPIFolder

    Dim myItem As Outlook.MailItem
    Dim myAttachment As Outlook.Attachment
    Dim I As Long

    Set myOlapp = CreateObject("Outlook.Application")
    Set myNameSpace = myOlapp.GetNamespace("MAPI")
    Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
    Set yourFolder = myNameSpace.GetDefaultFolder(olFolderInbox)

    Set myFolder = myFolder.Folders("folder1")
    Set yourFolder = yourFolder.Folders("folder2")

    For Each myItem In myFolder.Items
        If myItem.Attachments.Count <> 0 Then
            For Each myAttachment In myItem.Attachments
                I = I + 1
                myAttachment.SaveAsFile "C:\arthur\test.csv"

            Next
        End If

        myItem.Move yourFolder

    Next
End Sub

推荐答案

要被识别为规则向导的正确脚本宏,该宏必须具有预期的参数:

To be recognized as proper script macro for the Rule Wizard, the macro has to have the expected parameter:

Sub myRuleMacro(item as Outlook.MailItem)

MSDN 文章(对 Outlook 2007/2010/2013/2016 仍然有效)

MSDN article (still valid for Outlook 2007/2010/2013/2016)

相关文章

关于启用脚本运行规则的文章 否则由于安全原因被禁用
(注册表项 EnableUnsafeClientMailRules).

Article about enabling run-a-script rules otherwise disabled due to security reasons
(registry key EnableUnsafeClientMailRules).

这篇关于我在“运行脚本"选择框中看不到我的 VBA 宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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