Consulting

Results 1 to 4 of 4

Thread: CALLING MACROS FROM SINGLE USERFORM

  1. #1
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location

    CALLING MACROS FROM SINGLE USERFORM

    Is the following possible in VBA:

    I have 3 procedures, let's call then A, B & C that perform tasks in 3 different workbooks. Each procedure consists of several macros that run in sequence to produce the desired result.

    At the start of each one of the procedures, users are required to provide information used in the code via a userform. As soon as the userform is unloaded the next part of each procedure is called. However, the same userform is used in all three procedures.

    My question is, can all three of the next steps somehow be called from the one userform code?
    So when procedure A is run, next step A is called, when B is run next step B is called from the same userform and so on.

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .
    Sounds like (from your description), when the form is unloaded, you will need to load it again so the user can see it.

    The alternative would be to create three different forms, all looking the same. Each form would be loaded, one at a time, as the
    different procedures arise.

  3. #3
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi Deanp!
    Private Sub CommandButton1_Click()
    Dim s$
    s = InputBox("Pls input ...")
    Select Case s
      Case "A"
        Call testA
      Case "B"
        Call testB
      Case "C"
        Call testC
    End Select
    End Sub
    Sub testA()
      MsgBox "testA is be called, it will call nextstepA"
      Call nextstepA
    End Sub
    Sub nextstepA()
      MsgBox "nextstepA is be called"
    End Sub
    Sub testB()
      MsgBox "testB is be called, it will call nextstepB"
      Call nextstepB
    End Sub
    Sub nextstepB()
      MsgBox "nextstepB is be called"
    End Sub
    Sub testC()
      MsgBox "testC is be called, it will call nextstepC"
      Call nextstepC
    End Sub
    Sub nextstepC()
      MsgBox "nextstepC is be called"
    End Sub

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Here's simple example

    1 UserFrom

    3 high level callable macros (on worksheet) calling the 1 userform to get a number

    3 lower level functions called in each of the 3 upper level macros
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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