Send .Send function (CDO Mail) to background process

那年仲夏 提交于 2020-01-16 09:38:16

问题


The Workbook Hangs until .Send function ends then procedures running have finished.

There is a procedure which contains below snip code, calling with another one.

.AddAttachment below has about 5MB file passed to.

When the VBA code is running, it blocks the main thread, hence the freezing.

Some VBA functions (such as printing a Word document) have the option to be sent to a background process. (.PrintOut Background:=True)

Is it possible to sent .Send function to a background to have the macro continue while CDO Mail sends with attached file?

The code snip is:

Dim iMsg As Object
Dim iConf As Object

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

With iMsg
    Set .Configuration = iConf
    .To = strTo
    .ReplyTo = "Email Address"
    .From = """Sender Name (Email Address)"" <EmailAddress>"
    .Subject = strSubject
    .TextBody = strBody
    .AddAttachment ThisWorkbook.Path & "\Temp\" & ThisWorkbook.Name
    .Send
End With

来源:https://stackoverflow.com/questions/48132209/send-send-function-cdo-mail-to-background-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!