VBA - 无法进行传出呼叫,因为应用程序正在调度输入同步呼叫
VBA - An outgoing call cannot be made since the application is dispatching an input-synchronous call
我想使用 Microsoft Visual Basic for Applications 通过代码发送电子邮件。在 Tools/References 下选中 Microsoft Outlook 12.0 对象库。代码编译无错。该代码在两台不同的机器上运行良好,但是当我在第三台机器上测试它时,它在执行第 2 行时出现错误。
Dim email As Outlook.MailItem
Set email = Application.CreateItem(olMailItem)
email.To = "myemailaddress@gmail.com"
email.Subject = "Subject"
email.Body = "Body"
email.Send
Set email = Nothing
我查看了很多关于此错误的帖子,但找不到匹配的解决方案。预先感谢您的帮助。
该代码具体何时执行?是不是 运行ning 来自托盘图标事件处理程序?
启动一个计时器,当计时器触发时(您将退出传入的 RPC 调用),运行 您上面的代码。
谢谢大家最初的回复。原来解决问题的方法是使用 SEO 发送电子邮件。这是对我有用的代码:
Set objMessage = CreateObject("cdo.message")
Set objConfig = CreateObject("cdo.configuration")
Set Flds = objConfig.Fields
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "myExchangeServerName"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myDomain\user@myDomain.com"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "myPassword"
Flds.Update
Set objMessage.Configuration = objConfig
objMessage.To = "toEmail@someDomain.com"
objMessage.From = "fromEmail@someOtherDomain.com"
objMessage.Subject = "My Subject"
objMessage.Fields.Update
objMessage.HTMLBody = "<p><span style=""font-family: 'Calibri','Arial','sans-serif'"";>My Body Text</span></p>"
objMessage.AddAttachment "C:/path/filename.txt"
objMessage.Send
我想使用 Microsoft Visual Basic for Applications 通过代码发送电子邮件。在 Tools/References 下选中 Microsoft Outlook 12.0 对象库。代码编译无错。该代码在两台不同的机器上运行良好,但是当我在第三台机器上测试它时,它在执行第 2 行时出现错误。
Dim email As Outlook.MailItem
Set email = Application.CreateItem(olMailItem)
email.To = "myemailaddress@gmail.com"
email.Subject = "Subject"
email.Body = "Body"
email.Send
Set email = Nothing
我查看了很多关于此错误的帖子,但找不到匹配的解决方案。预先感谢您的帮助。
该代码具体何时执行?是不是 运行ning 来自托盘图标事件处理程序?
启动一个计时器,当计时器触发时(您将退出传入的 RPC 调用),运行 您上面的代码。
谢谢大家最初的回复。原来解决问题的方法是使用 SEO 发送电子邮件。这是对我有用的代码:
Set objMessage = CreateObject("cdo.message")
Set objConfig = CreateObject("cdo.configuration")
Set Flds = objConfig.Fields
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "myExchangeServerName"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myDomain\user@myDomain.com"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "myPassword"
Flds.Update
Set objMessage.Configuration = objConfig
objMessage.To = "toEmail@someDomain.com"
objMessage.From = "fromEmail@someOtherDomain.com"
objMessage.Subject = "My Subject"
objMessage.Fields.Update
objMessage.HTMLBody = "<p><span style=""font-family: 'Calibri','Arial','sans-serif'"";>My Body Text</span></p>"
objMessage.AddAttachment "C:/path/filename.txt"
objMessage.Send