【问题标题】:VBA code not running on Outlook restartOutlook 重新启动时未运行 VBA 代码
【发布时间】:2015-09-17 17:23:43
【问题描述】:

当我关闭并重新启动 Outlook 时,宏不起作用。

此代码将在 Outlook 中发送邮件的主题和附件之前进行验证。

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim lngAns                  As Long
Dim varArray                As Variant
Dim strWordFound            As String

varArray = Array("PFA", "Attached", "Enclosed", "File", "Report")

For lngCount = LBound(varArray) To UBound(varArray)
    If InStr(1, Item.Body, varArray(lngCount), vbTextCompare) Or InStr(1, Item.Subject, varArray(lngCount), vbTextCompare) Then
        strWordFound = strWordFound & "," & varArray(lngCount)
    End If
Next
strWordFound = Mid(strWordFound, 2)
If Len(strWordFound) > 0 And Item.Attachments.Count = 0 Then
    If MsgBox("Found No Attachments but the Word(s): " & _
                    strWordFound & vbTab & vbCr & "Do you want to send the mail anyway?", _
                            vbYesNo + vbQuestion, "Attachment Missing") = vbNo Then Cancel = True
End If
If Len(Trim(Item.Subject)) = 0 Then
    If MsgBox("Subject is Empty. Are you sure you want to send the Mail?", _
                vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Subject Missing") = vbNo Then Cancel = True

End If

End Sub

【问题讨论】:

  • 此代码无法在启动时运行。既然您知道“此代码将在发送邮件之前进行验证”,那么关于在发送邮件之前代码未运行的问题。
  • 当我保存代码然后尝试发送没有任何主题或附件的邮件时。有用。如果我关闭 Outlook 应用程序,然后撰写邮件并发送没有任何主题行或附件的电子邮件。此代码不起作用。这就是挑战。如果可以,请提供帮助。

标签: vba outlook


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多