One macro two versions

  • Thread starter Thread starter Shatin
  • Start date Start date
S

Shatin

I have a macro which is normally invoked by a button on a worksheet. Before
the macro is run, there is a MsgBox prompt asking for confirmation.

Now I want to call this macro from another macro. In this case, I want to
skip the MsgBox prompt part and go ahead with the macro right away.

How can I check whether the macro has been called by a button or another
macro? Or is there a better way handling this problem?

TIA
 
Hi Shatin

Look in the VBA help for application.caller if you use forms buttons
 
I would have the code for the button be something simple such as

response = msgbox("Do you want to run the macro....")
If response = vbYes then
Call MacroName
Endif

The you can still call MacroName from another macro that does not require
the user to respond to the message box prompt.
 
Actually I simplified the situation somewhat when I posed the question. In
fact I have buttons on several worksheets that call the same macro. So
application.caller doesn't always return the same unique button name. I was
hoping that something like this might work

If application.caller.name like "button*"

but apparently not.
 
That is a simple and practical solution and maybe that's what I am actually
going to do. Still, I am curious to know what
the code would be like if I want to have just one macro.
 

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

Back
Top