# VBA new mail event



## Lavina (Feb 5, 2019)

Hello guys,

I'm trying to replace people at my work and the next step is running specific macros when certain emails are received.

I am using office 365, and I'm not sure what is going wrong.

I found multiple examples, but none of them seem to work, an example: https://docs.microsoft.com/en-us/office/vba/api/outlook.application.newmail

But once run i get the compile error: user-defined type not defined

The error seems to originate from:

Public WithEvents myOlApp As Outlook.Application 

and I have no practice with working with applications that are outside excel, any help is much appreciated!


https://www.tachytelic.net/2017/10/how-to-run-a-vba-macro-when-new-mail-is-received-in-outlook/
This would get me all the info i need, but i cannot get it to work either, really not sure what im missing


----------



## CalcSux78 (Feb 5, 2019)

Sounds like you need to load the Outlook References.

in VB, click on Tools > References.  Scroll down and select the Microsoft Outlook XX.0 Object Library.


----------



## Lavina (Feb 5, 2019)

If only all my problems were that easy to fix :D thank you very much for help!


----------

