sub or function not defined error - HELP!!

A

adenke

I have created a Macro in VB in Outlook 2007, and when I run it, I get a "Sub
or function not defined" error message box. I have not been able to
troubleshoot this properly. Once I click OK on the message box, I can just
press F5 and the macro runs perfectly, but I would rather not have this
annoying step. Where should I look for the problem
 
E

Eric Legault [MVP - Outlook]

Turn on Option Explicit and try compiling your code - it'll tell you where
there are calls for functions or procedures that don't exist.
 
A

adenke

I did that. I assume that Option Explicit goes in the Declarations section of
the module. The behavior is exactly the same. When I try to compile the code,
it doesn't seem like anything happens (other that "Complile Spamdeath" (my
project name) turns grey after running "Compile Spamdeath once). No errors
pop up or anything. If I add the statement "bob=mickeymouse(), then it shows
me that mickeymouse() doesn't exist, so I'm guessing that the sub or function
not defined error is a red herring for the actual problem.

All I have in my project is this:

Option Explicit

Public Sub SpamDeath()

UserForm1.Show
End Sub

Plus a user form with some ListBoxes and CommandButtons and the code
associated with those.

I am throroughly confused here. I do a lot of VB programming, but this is my
first macro through MSOffice attempt since a much earlier version of Excel.

It may be worth noting that I went into the VB Editor first to create the
project and then later did the "Create" step from the macro directory at
which point I added the line of code to load my form. Perhaps that was wrong?
 
A

adenke

Forgive my ignorance of Outlook VB Macros - this is very frustrating.

The error occurs before my form loads. I have more code, but it is all on
the controls on userform1, which doesn't even load when I go through the menu
tree Tools->Macro->Macros->SpamDeath->Run. As soon as I click on Run, I get
the sub or function not defined messagebox. I did what you suggested and put
on error statements in absolutely every subroutine in my project, and those
errors never get triggered. This appears to be something in the initial
running of the Macro before it executes. My form never loads, just the
messagebox...
 
A

adenke

Thanks for your help. I still don't know what was wrong, but I fixed it by
creating a new macro and posting the exact same code into it. Something was
clearly messed up with the first macro.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top