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?
Figure 1 Running the "Test" macro in Microsoft Outlook
Figure 2 "Sub or Function not defined" error, with module tree in the background
Outlook. On the Developer tab, click Visual Basic. On the Tools menu, click Options. On the Other tab, click Advanced Options, and then select the Show Developer tab in the Ribbon check box.
If we run this code using the F5 key or manually, we will get Run time error '9': “Subscript out of Range.” To fix this issue, we need to assign the length of an array by using the “ReDim” word. This code does not give any errors.
“Sub or Function not Defined” is a compile error that occurs when VBA cannot find a procedure or other reference by name. A typo is the most common cause of this message.
The most common way to define a function in VBA is by using the Function keyword, followed by a unique function name and it may or may not carry a list of parameters and a statement with End Function keyword, which indicates the end of the function.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With