Outlook vba 无法将电子邮件作为分配给规则的脚本发送 [英] Outlook vba cannot sent email as script assigned to rule

查看:108
本文介绍了Outlook vba 无法将电子邮件作为分配给规则的脚本发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在 Outlook 中运行一个 vba 脚本作为规则1.捕获"带有附件的特定邮件(Excel)2.将此附件另存为文件并在此文件中进行一些更改3. 通过电子邮件发送这个改变"的文件.

I have to run a vba script as a rule in Outlook that 1. "Catch" specific mail with attachment(Excel) 2. save this attachment as a file and do some changes in this file 3. send by email this "changed" file.

P.1 和 P.2 我已经完成了,但是我无法发送和发送电子邮件.当我收到主题中包含特定单词的消息时,我会尝试使用这个简单的代码作为规则运行此脚本:

P.1 and P.2 I've already done, but I can't send and email. I try this simple code as a rule when I've got a message with specific words in subject run this script:

 Sub sendemail()
 Dim OutlApp As Object
 On Error Resume Next
  Set OutlApp = GetObject(, "Outlook.Application")<---use this instance of outlook            
 If Err Then
 Set OutlApp = CreateObject("Outlook.Application")
 IsCreated = True
 End If
 OutlApp.Visible = True
 On Error GoTo 0
 With OutlApp.CreateItem(0)
.To = "aaaaa@bbbb.com"
.Subject = "test"
.Display    
 End With
 Set OutlApp = Nothing
 End Sub

当我在 VBA 项目中作为宏 (F5) 运行时,一切正常,出现邮件,但运行规则时没有任何反应.有任何想法吗?问候,

when I run as a macro (F5) in VBA Project everything went OK, mail appears, but nothing happened when I run the rule. Any Ideas? regards,

推荐答案

运行脚本代码的第一行必须是这样的.

The first line of run a script code has to look like this.

Sub name(itm as mailItem)

Sub name(itm as meetingItem)

itm"是正在接收的邮件或会议.

"itm" is the mail or meeting that is being received.

在您的情况下,您必须已经有另一个接收它的子并执行 P1 和 P2.现在您将在 P2 之后调用 sendemail 代码.

In your case you must already have another sub where you receive itm and do P1 and P2. Now you would invoke sendemail code after P2.

Sub P1_P2_sendemail(itm As mailItem)

' P1
' P2

With CreateItem(0)
    .To = "aaaaa@bbbb.com"
    .Subject = "test"
    .Display
End With

End Sub

这篇关于Outlook vba 无法将电子邮件作为分配给规则的脚本发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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