Consulting

Results 1 to 11 of 11

Thread: Excel to Outlook Run Time Error 287 & Remove Default Signature

  1. #1
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location

    Excel to Outlook Run Time Error 287 & Remove Default Signature

    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:-

    2021-07-07_16-42-35.jpg

    This shows up on this line :-

    2021-07-07_16-42-19.jpg

    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
    Attached Files Attached Files

  2. #2
    The second part of the problem is the easy part - remove the line
    oRng.collapse 1
    shown 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?
    Attached Files Attached Files
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    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.

  4. #4
    Check the vba editor > tools > references on both PCs and see if they match.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    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
    Attached Images Attached Images
    Last edited by HTSCF Fareha; 07-08-2021 at 11:34 PM.

  6. #6
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    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/Fo...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

  7. #7
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Have you tried something as simpleminded as .Signature = ""
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  8. #8
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    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!

  9. #9
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    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.

  10. #10
    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

  11. #11
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •