0
votes

I am trying to send an email, from MS-Project using MS-Outlook, to notify the next resource when a task is completed.
I want to send an email to verify the main commands are right.
With Google I found a VBA macro that creates an email.
I 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 opens a window without sending an email, 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.

I am running the virtualized MS-Project application while MS-Outlook is installed on my PC. There seems to be an issue with the integration of the virtual MS-Project with the installed MS-Outlook.

1
I think I have seen where the problem may be. I am running the virtualized MS-Project application while MS-Outlook is installed on my PC. There seems to be an issue with the integration of the virtual MS-Project with the installed MS-Outlook. Anyone have experience in this subject?Miguel Santos

1 Answers

0
votes

You need to either add Outlook to the project references or treat all variables as generic object:

Sub CreateMail()
  
 Dim OutApp As Object
 Dim OutMail As Object

 Set OutApp = CreateObject("Outlook.Application")
 Set OutMail = OutApp.CreateItem(0)
 
 OutMail.Subject = "Mail to myself"
 
 OutMail.Display
 
End Sub