PDA

View Full Version : Excel to Outlook Run Time Error 287 & Remove Default Signature



HTSCF Fareha
07-07-2021, 11:06 AM
I have the attached Excel macro that has a UserForm that is instigated from a command button. This allows a selection of an email recipient from a list and two TextBoxes to add extra detail. There is then the "Prepare Email" button which does exactly that and populates the relevant areas for review prior to sending. On my home setup running Office 2019 this works fine, but when at work which uses Office 2016, I get the following:-

28705

This shows up on this line :-

28704

This is part one and my main problem.

The second part is that if a user has a default signature already setup in Outlook, then I would like this to be removed. I have been scouring online and have found mention of
Set oBookmark = objDoc.Bookmarks("_MailAutoSig") but am uncertain if this is the most efficient way or if it would work in my file. Help for these two things would be very much appreciated.

Thanks!
Steve

gmayor
07-07-2021, 09:27 PM
The second part of the problem is the easy part - remove the line
oRng.collapse 1shown in your screen shot. That line moves the range to the start of the message. To eliminate the signature, you need to keep the range as the whole message.
I have made a few minor changes to correct some anomalies in your process. It all works here. Is Outlook the default e-mail application at work?

HTSCF Fareha
07-08-2021, 10:11 PM
Thanks Graham for looking at this one for me.

The code works okay again on my home setup, but again I am getting that error code on the same line at work.

Outlook (Office 2016) is the default email application at work. In fact, it is the only method that we have.

gmayor
07-08-2021, 10:24 PM
Check the vba editor > tools > references on both PCs and see if they match.

HTSCF Fareha
07-08-2021, 11:21 PM
The only differences were that MS Word and MS Outlook Object libraries were ticked in my work set up. Removing these so that both were identical still throws up the same error on the same line.

I also tried increasing the delay to
Sleep 2000

HTSCF Fareha
07-15-2021, 04:18 AM
Graham has very kindly reviewed the code and "tidied" things up, but this is still throwing up the same error on the same line as in my original post.

Annoyingly, it works fine on my "home" Office 2019 set-up, but refuses to play ball on the "work" Office 2016 set-up.

I found this link here https://social.msdn.microsoft.com/Forums/en-US/81e8225a-583a-41bf-b988-414ce77f6832/using-vba-to-send-an-outlook-email-gives-error-287?forum=exceldev, which mentions Outlook Security Guard (?), but again still no joy.

I'd really appreciate someone who could make a suggestion to be able to get this working.

Thanks!
Steve

SamT
07-15-2021, 08:28 AM
:dunno Have you tried something as simpleminded as .Signature = ""

HTSCF Fareha
07-15-2021, 11:09 AM
Sorry Sam, I should've made it clear in my last post. Graham had actually solved the signature part. Its just that pesky Run Time Error 287 that's causing issue!

HTSCF Fareha
08-22-2021, 06:24 AM
I still haven't managed to get rid of the run time error code '287' in our work's Office 2016 setup. It's really annoying as the updated version provided by Graham in post #2 (sorted the signature part) works great at home on my Office 2019 setup.

Just to recap, I've ensured that the object references are identical and Outlook is the default (only) email client at work. Desperate to get this one going.

arnelgp
08-22-2021, 07:43 AM
what bitness of office do you have at home and office (x32 or x64)?
anyway you have wrong declaration of dwMilliseconds (only long for both x32 and x64).
Longptr only applies to window handle or any pointer.

'arnelgp
#If VBA7 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If

HTSCF Fareha
08-24-2021, 02:13 AM
Thanks for looking at this.

If I'm assuming correctly that you put the code like this


Option Explicit

#If VBA7 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If

Public sRMSnumber As String, sForce As Variant, sOfficer As Variant

Then I'm still getting the same error.

Both versions of Office are 32 Bit.

The only reason I introduced the delay is I read somewhere (can't remember where) that this worked, although its not happening with my project.