Consulting

Results 1 to 2 of 2

Thread: SOLVED: Run Procedure from a macro

  1. #1
    VBAX Regular
    Joined
    Jun 2004
    Posts
    28
    Location

    SOLVED: Run Procedure from a macro

    Dear Friends,

    Thanks for the previous reply. I have another question though.
    I want to directly run a procedure say MsgBox("hello") from a macro 'test'.
    I defined the openModule action in the macro 'test' but it does exactly what it says opens the module at procedure hello. What do I have to do to run the procedure?

    Thanks,
    G.

  2. #2
    VBAX Tutor SJ McAbney's Avatar
    Joined
    May 2004
    Location
    Glasgow
    Posts
    243
    Location
    Quote Originally Posted by banavas
    Thanks for the previous reply.
    Does that mean the previous question is resolved. Please say so on the thread so that I can close it.

    I want to directly run a procedure say MsgBox("hello") from a macro 'test'.
    I defined the openModule action in the macro 'test' but it does exactly what it says opens the module at procedure hello. What do I have to do to run the procedure?
    I would advise against using macros in a database. The only exception would be an auto-executing macro (called autoexec).

    Macros waste space, are restricting, and offer no scope for handling errors. If a macro fails then you just can't manage the after effects.

    Okay, but to answer your question: the code in the module must be a Function and not a Sub.

    You would use the RunCode method to execute the function.

    i.e.

    [vba]MyFunction()[/vba]

    In the instance you've stated though, you can also use the MsgBox method in the macro's method list to do the message box anyway. If using a function in the MsgBox method of a macro then you must place an equals sign before the function

    i.e.

    [vba]=MyFunction()[/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •