'Outlook.MailItem' is not defined. Invoke code problem


I want to use Invoke Code to read a local .msg file to get an attached file.

Dim OL As New Microsoft.Office.Interop.Outlook.Application
Dim Msg As Outlook.MailItem 
Msg = OL.CreateItemFromTemplate("C:\Users\az27355\Desktop\tempatt\original_email.eml.msg")

'TODO attached pdf = Msg.Attachment

First problem was to import Microsoft.Office.Interop.Outlook. I’ve seen others with similar issues and their solution only helped me partially.
The code failed at line 1 so I had to manually add to the xaml:

But the code still fails:

error BC30002: Type ‘Outlook.MailItem’ is not defined. At line 2



Please look into Read a .msg file and save attachement

This might help you.


I saw it but I’d rather not be depending on an external script. Thanks though.
It just makes deployment and maintenance more troublesome.