我有一段脚本,随着时间的推移拼凑起来。最近我们需要在Outlook中使用一个插件导致了一些问题。基本上我们会得到两次提示,因为当使用插件时,电子邮件最终会被销毁并用特定的附件文件名重新创建。此时会再次提示用户。我试图在For循环中工作,如果它找到了这个附件,就跳过脚本。但是,当我添加For循环时,它似乎忽略了整个脚本。我对VBA的经验有限,所以我确信这是我的语法或用法的问题。请参见下面的脚本:VBA展望脚本
Private Sub Application_ItemSend _
(ByVal Item As Object, Cancel As Boolean)
Dim strMsg As String
Dim Atmt As Variant
'strMsg = Item.Class
If Item.Class = "43" Then
For Each Atmt In Item.Attachments
If VBA.Right(Atmt.FileName, 3) = ".sf" Then
GoTo NonEmailError
End If
Next Atmt
If Item.CC = "" Then
strMsg = "To recipients: " & Item.To & vbCrLf & _
"Are you sure you want to send this message?"
Else
strMsg = "To recipients: " & Item.To & vbCrLf & _
"Cc recipients: " & Item.CC & vbCrLf & _
"Bcc recipients: " & Item.BCC & vbCrLf & _
"Are you sure you want to send this message?"
End If
Else
GoTo NonEmailError
End If
' Exit Sub
' Ignore errors for now.
On Error GoTo NonEmailError
' Prompt user to fill in subject
If Item.Subject = "" Then
MsgBox "You must enter a subject.", 48, "Empty Subject"
Cancel = True
GoTo NonEmailError
End If
' Exit Sub
' Prompt user to verify E-Mails
If MsgBox(strMsg, vbYesNo + vbQuestion _
, "Send Confirmation") = vbNo Then
Cancel = True
End If
Exit Sub
NonEmailError:
' The item being sent was not an e-mail and so don't prompt the user anything
Exit Sub
End Sub
有几点意见:1)不管电子邮件是否有附件,这两个提示都会显示出来吗? 2)哪一行是与第一个提示相关联的,哪一行是第二个? 3)它可能是一个好主意,而不是一个'对象'的工作,'暗淡olMI作为Outlook.MailItem ---如果TypeName(Item)=“MailItem”然后---设置olMI =项目---'做你的东西---如果“。 –