使用CDO.sys dll在VBA中发送消息会使Excel冻结 [英] Using CDO.sys dll for sending messages in VBA freezes Excel
问题描述
使用CDO.sys从启用了VBA的Excel应用程序发送电子邮件时,我面临一个奇怪的问题.我使用了以下代码,位于 https://www.rondebruin.nl/win/s1/cdo.htm :
I'm facing with a strange problem using CDO.sys for sending email messages from a VBA-enabled Excel application. I've used the following code, found at 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,然后再次将其打开.有解决问题的建议吗?提前致谢,埃米利奥(Emilio)
Now, the code works fine and the emails are sent. However, after the first email is sent, immediately Excel becomes unresponsive on many different commands. For example, normal operations like changing the font dimensions in cells or applying a conditional formatting are not active anymore. In addition, Excel appear slow executing everything. The only solution to fix this condition is to close Excel and open it again. Any suggestion to fix the problem? Thanks in advance, Emilio
推荐答案
绝对出乎意料,但是删除Msgbox调用电子邮件发送至"可以解决问题!
Absolutely unexpected, but removing the Msgbox call "Email sent to" solved the problem!
这篇关于使用CDO.sys dll在VBA中发送消息会使Excel冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!