Outlook: Create a mail with VBA is broken when GetInspector is called

Outlook 365 version 2009 build 13231.20418

When sending a mail in VBA the mail is saved in the Drafts folder but not send if GetInspector is called

Example

    Sub Create_Mail_in_Outlook()
        Dim OutlookApp As Object
        Dim OutlookMail As Object
        Set OutlookApp = CreateObject("Outlook.Application")
        Set OutlookMail = OutlookApp.CreateItem(0)
        On Error Resume Next
        ' insert your mail adress 
        OutlookMail.To = "..."
        OutlookMail.Subject = "Test"
        Set myInspector = OutlookMail.GetInspector
        Set OldBody = OutlookMail.Body
        OutlookMail.Body = "Mail created in VBA" + OldBody
        OutlookMail.Send
        On Error GoTo 0
        Set OutlookMail = Nothing
        Set OutlookApp = Nothing
    End Sub

Without calling GetInspector the mail is sent. But I need to call GetInspector because I want to keep the signature.

With Outlook 365 version 2008 (16.0.12127.20638) sending a mail works fine even with calling GetInspector.
Hi Wolfgang,

When I change Send to Display, the signature is still missing... unless I switch to HTMLbody. In any event, it used to work in old versions but is broken in the correct version, correct? I'll pass it along to support.
--
Diane Poremsky
M365 MVP, specializing in Outlook, Exchange, and Microsoft 365 apps.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

With some more testing - if I add OutlookMail.Display before the send line, it sends.

I'm using this as the body line:
OutlookMail.HTMLBody = "Mail created in VBA" & OutlookMail.HTMLBody

as the signature wasn't added using oldbody. or
--
Diane Poremsky
M365 MVP, specializing in Outlook, Exchange, and Microsoft 365 apps.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Yes, with OutlookMail.Display the mail is sent. But then the mail is shown for a short time. This is not acceptable. 

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Here is an improved example without surpressing the error message:

Sub Create_Mail_in_Outlook()

        Dim OutlookApp As Object

        Dim OutlookMail As Object

        Set OutlookApp = CreateObject("Outlook.Application")

        Set OutlookMail = OutlookApp.CreateItem(0)

        ' insert your mail adress

        OutlookMail.To = "..."

        OutlookMail.Subject = "Test"

        Dim myInspector As Object

        Set myInspector = OutlookMail.GetInspector

        Dim OldBody As String

        OldBody = OutlookMail.Body

        OutlookMail.Body = "Mail created in VBA" + OldBody

        OutlookMail.Send

End Sub

When running an error message is shown from OutlookMail.Send

Run-Time Error 5
Invalid Procedure Call or Argument

With Outlook 365 version 2008 (16.0.12127.20638) no error occurred and the mail was sent

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Unfortunately, until it is fixed, it is an easy option to implement. I have a macro that will insert the signature using a filesystemobject. Or you can rollback to the earlier version.

I passed it along to support, but it's too soon to know when it will be fixed.
--
Diane Poremsky
M365 MVP, specializing in Outlook, Exchange, and Microsoft 365 apps.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Hi Wolfgang,

I'm having the same problem, but in C# the error is "System.ArgumentException: Value does not fall within the expected range."

Hopping that MS fixes this error quick.

Also I found out that if you call myInspector.Close(olSave) then the send does not give the error but only if Outlook is running.

If it is closed AND doing a cold start (meaning it's not showing the outlook icon on the tray with the gear indicating that is begin externally accessed) it gives the following error "System.Runtime.InteropServices.COMException (0x800706BA): The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

I have an update from my contacts - it is due to a regression caused by smartlinks code. I don't have an ETA for a fix though. 

Diane Poremsky [M365 Apps & Services MVP]
My specialty is Outlook and Microsoft 365 issues.
https://www.slipstick.com
https://www.outlook-tips.net
Mark Yes below if it helped or resolved your issue.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated March 29, 2023 Views 582 Applies to: