Call a VBA module

Solved
Hello,

Small programming issue.

I wrote a code in a module (Sub ex1 () )

I want to call the "Sub ex1" in another module (Sub_principal) and have it execute only once

Can you help me? Thank you

Have a nice day

8 answers

  • Votes
  • Date
  • Descending date
  1. Contributor
    Hello,

    you just need to write ex1 or Call ex1 in the main routine.

    Example:
    Sub Sub_principal() ... Call ex1 ... End Sub


    Best regards.
    --
    This guy wasn't the brightest, as he was naive.
    1. I already tried, the other problem is that it tells me "variable or procedure expected, not module".
      1. Hello,
        Just passing by, at what time did you receive this message?
        --
        Regards.
        The Penguin
        1. It's when I run my program (sub main()) in step-by-step mode.

          Shouldn't the variables of sub ex1() be declared in the main?
          1. Hello,
            If at the beginning of the module you have the instruction line [Option Explicit], you must declare the variables.
            Regards.
            The Penguin
        2. Good evening;

          Would you happen to have a module name called "ex1", by any chance?

          You can't name a Sub and a Module the same name....

          Have a good evening.
          1. Hello,

            To present my problem that is still not resolved.

            In Microsoft Visual Basic under Excel,

            I created 3 macros (starting with Sub... and ending with End Sub) in the module folder. In this same folder, I created a 4th one that I will call main, in which I would like to call the 3 macros (to execute them).

            Thank you for your help.
            1. Moderator
              Hello,
              If your VBA code is not "top-secret", I invite you, for a definitive and quick solution, to copy/paste the codes of the three procedures (I created 3 macros starting with Sub... and ending with End Sub) right here in a response. You'll see, you'll have your solution by the end of the day...
            2. It's not the content that matters, but the way of calling the procedures.

              I'm on the path to resolution, I'll keep you updated.
          2. In fact, I have in the module properties (name) named the same name as the one in the module at the Sub level...

            Since I changed to different names, I can now call my procedures.