Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I need a VBA event to call a function with parameters

Posted on 2011-09-08
6
Medium Priority
?
263 Views
Last Modified: 2012-05-12
What's the VBA syntax (in Excel 2007) to have an event call an internal VBA function I will write, passing in a few parameters. I want to resuse that function for  multiple events and to use the input parameter to differentiate calls to the same function from various events?

Thanks.
0
Comment
Question by:newbieweb
[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
  • 3
  • 3
6 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 2000 total points
ID: 36504162
Write the function like so:

Public Function Foo(ByVal RequestCode As Long, ByVal Variable1 As Variant, ByVal Variable2 As Variant) As Variant

    Select Case RequestCode
        Case 1:
            ' Do this
        Case 2:
            ' Do that
    End Select

End Function

Kevin
0
 

Author Comment

by:newbieweb
ID: 36504201
How do I execute it?
0
 

Author Comment

by:newbieweb
ID: 36504203
And what does "As Variant" do?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 81

Assisted Solution

by:zorvek (Kevin Jones)
zorvek (Kevin Jones) earned 2000 total points
ID: 36504213
Like so:

Public Sub SomeEventHandler()

    Dim MyResult As Variant

    MyResult = Foo(1, "A", 100)

End Sub

Kevin
0
 
LVL 81

Assisted Solution

by:zorvek (Kevin Jones)
zorvek (Kevin Jones) earned 2000 total points
ID: 36504226
"As Variant" defines the variable as a variant data type which means it can store any type of value.

You can also define a variable as Long, String, Date, an array, a collection, or any of many other types.

Kevin
0
 

Author Closing Comment

by:newbieweb
ID: 36504246
Thanks a lot!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
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.
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…

596 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