Cannot Open Office 2013 From Code

372 Views Asked by At

I have taken over development of a VB .NET 3.5 project. I need to add a reference to Microsoft.Office.Interop.Outlook for Office 2013, but it doesn't appear in my COM Reference list. I have Office 2013 installed. I have tried to find an installer for the PIAs, but I have not been able to find it for 2013.

enter image description here

Any suggestions?

UPDATE

I have upgraded to .NET 4, but I am not able to find the "Microsoft Outlook 15.0 Object Library" in my references (see above image). I tried installing them from the Office disk, but programability was already installed. I also installed the Office Developer Tools from the VS disk. I am at a loss on where to get this file from.

I tried switching to late binding with the following code:

Sub DisplayMail()
    Dim oAPP As Object
    Dim oItem As Object
    Const olMailItem As Long = 0

    oAPP = CreateObject("Outlook.Application")
    oItem = oAPP.CreateItem(olMailItem)
    With oItem
        .To = Me.EmailAddress
        .Subject = Me.MySubjectTextBox.Text.Trim.Replace("%", "%25").Replace("&", "%26")
        .Body = Me.EmailMessageBox.Text.Trim.Replace("%", "%25").Replace(vbCr, "%0d%0A").Replace("&", "%26")
        .Display()
    End With
End Sub

This works when Outlook is closed, but if I have Outlook open, I get a "Cannot create ActiveX component" error.

1

There are 1 best solutions below

0
Tim On

If you are working with Late Binding, and your application and Outlook are running under different access levels, you will get the "Cannot create ActiveX component" error.

In my case, Visual Studio was being run as Administrator, while Outlook was being run normally. I closed Outlook and opened it again as Administrator and there were no exceptions.