VBA-如何绑定早期的Outlook应用程序 [英] VBA - How to bind early Outlook application

查看:42
本文介绍了VBA-如何绑定早期的Outlook应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切正常,直到我完成Windows 10升级为止.然后,当我尝试从Excel发送电子邮件时,我开始收到此运行时错误:

Everything was working fine until I did the Windows 10 upgrade. Then I started getting this run-time error when trying to send an email from Excel:

运行时错误'-2147417851(80010105)':对象'_MailItem'的方法'To'失败

Run-time error '-2147417851 (80010105)': Method 'To' of object'_MailItem' failed

导致此问题的代码是:

Dim aOutlook As Object

....

Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)

aEmail.To = "emailaddress"

有人告诉我,这是因为我绑定了以后",并且这是一个错误(请参阅

I have been told that it is because I am binding 'later' and that this is a bug (see here). To bind 'early' I have tried the following:

Dim aOutlook As Outlook.Application
Dim aMail As Outlook.MailItem

Set aOutlook = New Outlook.Application
Set aEmail = aOutlook .CreateItem(olMailItem)

aEmail.To = "emailaddress"
aEmail.Display

这也不起作用,现在我得到了错误:

This doesn't work either and now I am getting the error:

Microsoft Office Excel正在等待另一个应用程序完成OLE操作.

Microsoft Office Excel is waiting for another application to complete an OLE action.

给出与最初相同的错误之前.谁能指出我要去哪里错了?

Before giving the same error as initially. Can anyone point out where I am going wrong?

推荐答案

这有点奇怪,但这是答案.在我为简单起见的问题中,我提出:

This is a little strange but here is the answer. In my question for simplicity I put:

aEmail.To = "emailaddress"

但我实际上有

aEmail.To = Cells(IntCurrentRow, 3)

其中Cells(IntCurrentRow,3)包含电子邮件地址.这似乎是问题所在.当我说以下内容时,它会起作用.

where Cells(IntCurrentRow, 3) contained the email address. This seemed to be the problem. When I put the following it worked.

emailAddress = Cells(IntCurrentRow, 3)
aEMail.To = emailAddress

我不确定为什么不直接获取地址,但是更改此地址可以解决此问题.感谢您的所有建议.

I am not sure why it wouldn't take the address directly but changing this has fixed the problem. Thanks for all the suggestions.

这篇关于VBA-如何绑定早期的Outlook应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆