Outlook VBA Sub or Function Not Defined

Hi,

I have a public sub routine in "ThisOutlookSession" that I am trying to call from a class module I have made. But getting an error message saying sub or function is not defined. I have checked the spelling of the sub so can't see why i cannot do this.

Thanks
mcs26Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PeteEngineerCommented:
A Sub or Function must be defined in order to be called. Possible causes of this error include:

Misspelling the procedure name.

Trying to call a procedure from another project without explicitly adding a reference to that project in the References dialog box.

Specifying a procedure that is not visible to the calling procedure.

Declaring a Windows dynamic-link library (DLL) routine or Macintosh code-resource routine that is not in the specified library or code resource.

To correct this error

Make sure that the procedure name is spelled correctly.

Find the name of the project containing the procedure you want to call in the References dialog box. If it does not appear, click the Browse button to search for it. Select the check box to the left of the project name, and then click OK.

Check the name of the routine.
0
mcs26Author Commented:
Hi Pete,

I have check the procedure name is spelled correctly. Is this an outlook issue when having code in the "ThisOutlookSession"?

Thanks
0
omgangIT ManagerCommented:
Just to clarify, you have a sub procedure named ThisOutlookSession and it is located in the ThisOutlookSession module?  I'm wondering if it is a naming confilict.  Can you try renaming the sub to see if the error goes away?
OM Gang
0
Chris Raisin(Retired Analyst/Programmer)Commented:
ThisOutlookSession is a class object of Outlook and so if you have written a method for it and made it public, all you have to do to call it is to say something like this in your calling module:

     
   ThisOutlookSession.MySub()

So if it is called (say) "ProcessItem()" and has a parameter of "mai" being an email item, inside "ThisOutlookSession" you would have:

    Public sub ProcessItem(mai as object)
    .....code
    ....code
    End Sub

and in your external module named (say)  "AutoFileit()"
you would have

   Private Sub AutoFileIt()
   Dim oSourceFolder As folder
   Dim oFolder As Object
   Dim oItem As Object
   Set oSourceFolder = Session.Folders("Personal Folders").Folders("Inbox")
   For Each oItem In oSourceFolder.Items
      ThisOutlookSession.ProcessItem(oItem)
   Next
 End Sub
     

Is this what you were after?
You must explicitly name the class for the method you are calling, and "ThisOutlookSession" is just another class. :-)

Intellisense should help you once you type "ThisOutlookSession" and follow it immediately with a "dot"

Of course your method must be "public" (which you have stated it is)

Cheers
Chris (Melbourne-Australia)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mcs26Author Commented:
Cheers Chris, xcatly what I was looking for!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.