Solved

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

Posted on 2011-03-22
3
205 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now