[vba] "Sub or Function not defined" when trying to run a VBA script in Outlook

As a first step in creating a VBA script to resize a currently selected image to 100% x 100%, I'm trying to reproduce the example in http://msdn.microsoft.com/en-us/library/ee814736(v=office.14).aspx. The macro is very simple:

Sub Test()
   MsgBox ("Hello world")
End Sub

The VBA script was simply created in "Project1" which opens by default when one presses Alt+F11. However, I keep getting the error "Sub or Function not defined" when trying to run the VBA script (Figures 1 and 2).

How can I make the VBA script 'accessible' to Outlook?

Running the "Test" macro in Microsoft Outlook Figure 1 Running the "Test" macro in Microsoft Outlook

enter image description here Figure 2 "Sub or Function not defined" error, with module tree in the background

This question is related to vba outlook

The answer is


This error “Sub or Function not defined”, will come every time when there is some compile error in script, so please check syntax again of your script.

I guess that is why when you used msqbox instead of msgbox it throws the error.


This probably does not answer your question, but I had the same question and it answered mine.

I changed Private Function to Public Function and it worked.


I need to add that, if the Module name and the sub name is the same you have such issue. Consider change the Module name to mod_Test instead of "Test" which is the same as the sub.


I think you need to update your libraries so that your VBA code works, your using ms outlook


I had a similar situation with this issue. In this case it would have looked like this

Sub Test()
   MsqBox ("Hello world")
End Sub

The problem was, that I had a lot more code there and couldn't recognize, that there was a misspelling in "MsqBox" (q instead of g) and therefore I had an error, it was really misleading, but since you can get on this error like that, maybe someone else will notice that it was cause by a misspelling like this...