briddums
briddums

Reputation: 1846

How to automate Office 2013 on Windows 8.1

I'm trying to automate Outlook to send an email. The simplified code I'm using is:

Dim outlook As Outlook.Application = Nothing

Try
    outlook = New Outlook.Application
Catch ex as Exception
    MsgBox(ex.Message)
End Try

Whenever I run it on Win8.1 with Outlook open I get the error message:

8008005 Server execution failed (Exception from HRESULT: 0x8008005 (CO_E_SERVER_EXEC_FAILURE))

Researching the error suggests that the reason is because I have Outlook open it fails to create a new instance. So I modified my code to:

Dim outlook As Outlook.Application = Nothing

Try
    If Process.GetProcessesByName("OUTLOOK").Length > 0 Then
        outlook = Marshal.GetActiveObject("Outlook.Application")
    Else
        outlook = New Outlook.Application
    End If

Catch ex as Exception
    MsgBox(ex.Message)
End Try

When I run it this time it tries connecting to the existing process and I get the error:

Operation Unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

So I can neither create a new instance or connect to an existing instance. I don't know what to do.

Upvotes: 0

Views: 468

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66286

CO_E_SERVER_EXEC_FAILURE means the security contexts of your app and Outlook are different. Make sure neither app runs with elevated privileges (e.g. Run As Administrator).

Upvotes: 2

Related Questions