Solved

How to have Excel buttons call a function with a parameter passed in Visual Basic for Applications?

Posted on 2011-03-22
3
207 Views
Last Modified: 2012-05-11

Hi,

I have a macro that creates buttons into my Excel sheet, and these buttons must call a macro. The difficult problem is, I need to tell which button called the macro.

One way to do this is passing the button as a parameter, and then getting it's ID (or row index):



Sub ArchiveTradeMacro(ByVal oButton As CommandButton)
MsgBox oButton.Caption
End Sub



But when I create the buttons, I could only set it to call a macro without parameters...  I can't call a macro while passing itself as a parameter.

So there's must be a way to do this.

Thanks.

0
Comment
Question by:nvs_victor
  • 2
3 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 35194072
You can get the button name using Application.Caller.

Kevin
0
 

Author Comment

by:nvs_victor
ID: 35194259

That settles it.    :)   I've spent like 3 hours on this problem... I esp hate it when Microsoft offers a very complex solution like
http://support.microsoft.com/kb/246299

And thanks to  this comment   MsgBox "I was called by " & Application.Caller                  from brettdj
That makes Application.Caller easier to use!

Thanks bud!
0
 

Author Closing Comment

by:nvs_victor
ID: 35194267
Thanks!

I was looking at Application.Caller, but thought it wouldn't work for me.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question