excelvbacdo.message

Using CDO.sys dll for sending messages in VBA freezes Excel


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

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


Solution

  • Absolutely unexpected, but removing the Msgbox call "Email sent to" solved the problem!