I am trying to be able to send an email from MS-Project using MS-Outlook. The scope is to notify the next resource when a task is completed. Before this scope, I want to simple send an email just to verify the main commands are right. I have been having a look with Google and I have found a very simple VBA macro that creates an email. I have tested this macro in MS-Excel and it works, but the same macro does not work in MS-Project. I have added reference to Microsoft Outlook 16.0 Object Library in both cases.
The macro only opens a window without sending an email, just to fill the 'To' field:
Sub CreateMail()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = New Outlook.Application
Set OutMail = OutApp.CreateItem(olMailItem)
OutMail.Subject = "Mail to myself"
OutMail.Display
End Sub
In MS-Project the macro stops in the following line:
Set OutMail = OutApp.CreateItem(olMailItem)
with this error message:
Run-time error '287': Application-defined or object-defined.
Could you help me to find where the problem in MS-Project is? I do not understand why the same code works in MS-Excel and not in MS-Project.