Solved

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

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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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