【问题标题】:Using CDO.sys dll for sending messages in VBA freezes Excel使用 CDO.sys dll 在 VBA 中发送消息会冻结 Excel
【发布时间】:2018-12-21 22:23:11
【问题描述】:

我在使用 CDO.sys 从支持 VBA 的 Excel 应用程序发送电子邮件时遇到了一个奇怪的问题。 我使用了以下代码,在https://www.rondebruin.nl/win/s1/cdo.htm 找到:

Sub SendMailCDO(FSubject As String, FBody As String, FFrom As String, FTo As String, FCc As String)

    Dim iMsg As Object
    Dim iConf As Object
    Dim Flds As Variant

    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1    ' CDO Source Defaults
    Set Flds = iConf.Fields
    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "myServerIPAddress"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Update
    End With

    With iMsg
        Set .Configuration = iConf
        .To = "mydestination"
        .CC = ""
        .BCC = ""
        .From = FFrom
        .Subject = FSubject
        .TextBody = ""
        .HTMLBody = FBody
        .Send
    End With
    MsgBox ("Email sent to " & FTo)
    Set iMsg = Nothing
    Set iConf = Nothing
    Set Flds = Nothing
End Sub

现在,代码工作正常,电子邮件已发送。但是,在发送第一封电子邮件后,Excel 会立即对许多不同的命令无响应。例如,更改单元格中的字体尺寸或应用条件格式等正常操作不再处于活动状态。此外,Excel 似乎执行一切都很慢。 解决此问题的唯一解决方案是关闭 Excel 并再次打开它。 有什么建议可以解决这个问题吗? 提前致谢, 埃米利奥

【问题讨论】:

    标签: excel vba cdo.message


    【解决方案1】:

    完全出乎意料,但删除 Msgbox 调用“Email sent to”解决了问题!

    【讨论】:

    • 难以置信!谢谢!
    【解决方案2】:

    这也发生在我身上。如果你有同样的问题,我得说删除 Msgbox 调用不一定能解决它。然而,之前的回答让我意识到我的代码中的任何内容都可能导致问题。

    所以...我尝试评论每一行,在我的情况下 删除对 Application.StatusBar 的调用就像一个魅力。不能摆出漂亮的状态,但至少Excel在发送电子邮件后不再冻结。

    希望对你有所帮助;)

    【讨论】:

      猜你喜欢
      • 2018-05-04
      • 2014-12-18
      • 1970-01-01
      • 1970-01-01
      • 2015-03-21
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      • 2016-06-13
      相关资源
      最近更新 更多