Solved

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

Posted on 2011-03-22
3
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

730 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