Code in Sub OKButton_Click to trigger actions depending on calling macro

H

Herman

Hello,
I'm looking for appropriate code in de OKButton of a multi item
listbox.
This code should trigger different actions depending on which
procedure the UserForm was called from.
I mean if the UserForm is called by macro A the action should be aaaa
and if it is called by macro B the action should be bbbb etc.

How can I refer to the calling macro in the OK Button code ?
Thanks a lot
Herman
 
C

Chip Pearson

Herman,

There is no built in way to determine what macro called the form.
You could add a Public variable to the form, set that variable to
the macro name prior to showing the form, then test that variable
when OK is clicked. E.g.,

' in the form's code module
Public CallingMacro As String
Public Sub OKButton_Click()
If CallingMacro = "A" Then
aaaa
ElseIf CallingMacro = "B" Then
bbb
' and so on
End If
End Sub

Then, in the procedures that call the form,

UserForm1.CallingMacro = "A"
UserForm1.Show


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top