VBA runtime 287 - possible late binding issue??

gordsky

Well-known Member
Joined
Jun 2, 2016
Messages
556
Office Version
  1. 2016
Platform
  1. Windows
Hi All,
Hoping someone out there will be able solve this one for me.

Majority of our machines at work run 2016 or newer but for some reason our office acquired a few that have 2010 installed. We use excel to automate email sending a lot and the below code works perfectly on all of the machines except the 2010 ones.

VBA Code:
Dim Outlook As Object, newEmail As Object, xInspect As Object, pageEditor As Object

Set Outlook = CreateObject("Outlook.Application")
Set newEmail = Outlook.createitem(0)

                
    With newEmail
        .SentOnBehalfOfName = "Company Email Goes Here"
        .display
         signature = newEmail.htmlbody
        .To = MyList ' this is defined in the larger code as the distribution list
        .Bcc = "The Boss Email Address"
        .subject = "My Subject Goes Here - "
        .htmlbody = "EMAIL TEXT IS HERE"
                    
        .ReadReceiptRequested = False
               
         Set xInspect = newEmail.GetInspector
         Set pageEditor = xInspect.WordEditor
    
         pageEditor.Application.Selection.Start = Len(.htmlbody)
         pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
         pageEditor.Application.Selection.pasteandformat (wdformatplaintext)
        .display
              
        .htmlbody = .htmlbody & signature
                                          
         Set pageEditor = Nothing
         Set xInspect = Nothing
         Application.CutCopyMode = False
         
    End With


On the 2010 machines it will fail in 2 places.

the first place is at
VBA Code:
signature = newEmail.htmlbody
having googled a lot on this I believe it is possibly due to the security levels in 2010 and effectively no work around - can manage without this but please correct me if I am wrong.

the second place it fails is at
VBA Code:
Set xInspect = newEmail.GetInspector
Set pageEditor = xInspect.WordEditor
and here it gives a runtime error of 287 - but only on the 2010 machines. Been trying to research around the possibility of late binding but not even sure Im starting in the right place.

Could somone help me out.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Having tested your code, and looked into it a bit, I am/was (frankly) equally confused, which I'm sure you don't want to hear someone when you've just asked for help! On the plus side, at least you can be comforted by the fact that it's not just you! :)

After having had to rewrite this reply a couple of times, and looked into it a little bit more than when I started to type this, I think you're possibly on the right path re: late binding being the issue - or at least, it was helpful enough in researching the issue for me to get to the point that I'm about to make, which is: The error 287 you're getting seems to be the result of an update in windows years ago (and not so much to do with late binding, per se) in terms of how Windows security will trust the creation/use of certain COM objects - which is what you're doing when you instantiate Outlook (through either early/late binding). You could test this by changing the code to early binding rather than late binding, but I have sneaking suspicion that you may still encounter the problem.

My reason for thinking this is from having seen the back and forth between two users on the VBA subreddit on this topic. I've linked to the final part of the exchange, but if you've not seen this already, perhaps try the suggested solution and see how that goes?

Please do let me know if this works, because you've got me curious now!
 
Upvote 0
Having tested your code, and looked into it a bit, I am/was (frankly) equally confused, which I'm sure you don't want to hear someone when you've just asked for help! On the plus side, at least you can be comforted by the fact that it's not just you! :)

After having had to rewrite this reply a couple of times, and looked into it a little bit more than when I started to type this, I think you're possibly on the right path re: late binding being the issue - or at least, it was helpful enough in researching the issue for me to get to the point that I'm about to make, which is: The error 287 you're getting seems to be the result of an update in windows years ago (and not so much to do with late binding, per se) in terms of how Windows security will trust the creation/use of certain COM objects - which is what you're doing when you instantiate Outlook (through either early/late binding). You could test this by changing the code to early binding rather than late binding, but I have sneaking suspicion that you may still encounter the problem.

My reason for thinking this is from having seen the back and forth between two users on the VBA subreddit on this topic. I've linked to the final part of the exchange, but if you've not seen this already, perhaps try the suggested solution and see how that goes?

Please do let me know if this works, because you've got me curious now!
Hi Dan, thanks for the reply.
I had already tried early binding but this gave cant find library issues on the 2010 machines in relation to 16 object library and then subsequently the same errors.
Im not entirely sure re the security aspect being linked to outlook as such. I took out the signature section of the code and put an on error resume next and the code will then run and generate an email with the .htmlbody text and fill all the relevant sections in it but it just wont process the two lines.

Ill try your suggestion above and then update
 
Upvote 0
m not entirely sure re the security aspect being linked to outlook as such.
Without a copy of Office 2010, I can't say definitively, but there is a bit of a hint in the the error handling code on this post of the DevHuts blog: VBA - Send HTML Emails Using Outlook Automation | DEVelopers HUT
VBA Code:
If Err.Number = "287" Then
        MsgBox "You clicked No to the Outlook security warning. " & _
               "Rerun the procedure and click Yes to access e-mail " & _
               "addresses to send your message. For more information, " & _
               "see the document at http://www.microsoft.com/office" & _
               "/previous/outlook/downloads/security.asp."
If you look at the comments, there is a bit more of a discussion re: this, and Dan points to his other blog post: Bypass Outlook's Security Prompt | DEVelopers HUT
So it may be the case that the user needs to press yes when presented with the security prompt. But if this is indeed the problem, and you can't realistically press yes each time, then the blog post helpfully lists some solutions.
 
Upvote 0
Hi Dan,

After going back and forth through the two links you sent and trying various aspects I am still unable to get this to run on the 2010 machines. Im completely stumped on this one and think will have to admit defeat...
 
Upvote 0
Without a copy of Office 2010, I can't say definitively, but there is a bit of a hint in the the error handling code on this post of the DevHuts blog: VBA - Send HTML Emails Using Outlook Automation | DEVelopers HUT
VBA Code:
If Err.Number = "287" Then
        MsgBox "You clicked No to the Outlook security warning. " & _
               "Rerun the procedure and click Yes to access e-mail " & _
               "addresses to send your message. For more information, " & _
               "see the document at http://www.microsoft.com/office" & _
               "/previous/outlook/downloads/security.asp."
If you look at the comments, there is a bit more of a discussion re: this, and Dan points to his other blog post: Bypass Outlook's Security Prompt | DEVelopers HUT
So it may be the case that the user needs to press yes when presented with the security prompt. But if this is indeed the problem, and you can't realistically press yes each time, then the blog post helpfully lists some solutions.
What about the security prompt point in this reply?
 
Upvote 0
What about the security prompt point in this reply?
yes i read up on that but I cant even get a security prompt to kick in. Just get a runtime error 287. If I debug and move the cursor passed the two lines i mentioned at the start I can get an email to generate without any prompts but it will have some of the info missing (the stuff that would have been picked up by the skipped lines.) Im going to re read the articles again at weekend when I have more time and will report back if I get any success
 
Upvote 0
I think that from what I read, it has something to do with the HTMLBody property. Perhaps try changing that to just .Body and see what happens?
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top