11
votes

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

6
I have narrowed down the issue I think - change the name of the module (or the sub) such that they are not equal - Cor_Blimey
Same problem after I changed the module name. I solved it by deleting the macro created (in the docx: in view tab/view macro/delete) - JinSnow

6 Answers

7
votes

I solved the problem by following the instructions on msdn.microsoft.com more closely. There, it is stated that one must create the new macro by selecting Developer -> Macros, typing a new macro name, and clicking "Create". Creating the macro in this way, I was able to run it (see message box below).

enter image description here

3
votes

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...

3
votes

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.

1
votes

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.

1
votes

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.

0
votes

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