PDA

View Full Version : CALLING MACROS FROM SINGLE USERFORM



DeanP
02-19-2019, 11:01 AM
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.

Logit
02-19-2019, 08:22 PM
.
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.

大灰狼1976
02-19-2019, 08:36 PM
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

Paul_Hossler
02-19-2019, 09:00 PM
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