Reputation: 5970
This was working until the Windows 10 upgrade.
I get this error when trying to send an email from Excel:
Run-time error '-2147417851 (80010105)': Method 'To' of object'_MailItem' failed
The code that caused this was:
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
Now I get the error:
Microsoft Office Excel is waiting for another application to complete an OLE action.
Before giving the same error as initially.
Upvotes: 0
Views: 3021
Reputation: 1
I was doing something similar but populating from a text box on a form.
oMail.To = frmMain.txtRecepients
didn't work. But,
oMail.To = frmMain.txtRecepients.value
did.
I'm wondering if it wasn't trying to set the .to to the object instead of the value of the object. Explicitly telling it to use the value seems to have fixed it.
Upvotes: 0
Reputation: 5970
This is a little strange but here is the answer. In my question for simplicity I put:
aEmail.To = "emailaddress"
but I actually had
aEmail.To = 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.
Upvotes: 4