Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
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…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

707 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

12 Experts available now in Live!

Get 1:1 Help Now