VBA - To Create List Box, which determines what section of code to run

Hello Experts,

Please bare with me as I try to explain... :)  And keep in mind, I basically only know how to copy & paste VBA code, and I can just barely slightly - customize code myself.

I am creating a macro to be run on an email, but if I continue the way I'm going, - I'll have many different macros.

Ultimately, I would like this...

1.)  Macro is run.
2.)  A userform opens, which contains a list box.
3.)  List box choices are: "Sample Request", "Product Return", "Quote Request".

If the user selects "Sample Request", I want the code to jump to my section of code for "Sample Request".  If the user selects "Product Return", I want the code to jump to the code for "Product Return".

I am hoping for someone to write some sample code, that will jump to sections of a code based on what is selected in a listbox on a userform.

I do know how to create a userform in Outlook, and I know how to add the listbox - but I have no clue how to code, or to get any values inside of the listbox, and I have no idea how to make the code execute certain sections depending on what is selected.

I HOPE that made sense!

Thank you in advance for your help!

~ Geekamo
LVL 1
GeekamoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
I don't do Outlook programming but here is an Excel workbook that shows the techniques. When you open the workbook type Ctrl+z which will run the ShowUserForm macro. Then choose any of the three listbox items.

To see the code, click the Visual Basic button or type Alt+F11. Then double-click on Module1 to see the macros or double-click on UserForm1 and then double-click the form itsef to see the userform code which is simply this:
Private Sub ListBox1_Click()
    Select Case ListBox1.ListIndex
        Case 0
            Sample_Request
        Case 1
            Product_Return
        Case 2
            Quote_Request
    End Select
End Sub

Private Sub UserForm_Initialize()
    ListBox1.AddItem "Sample Request"
    ListBox1.AddItem "Product Return"
    ListBox1.AddItem "Quote Request"
End Sub

Open in new window


The Initialize routine loads the listbox when the form opens and the ListBox1_Click code calls one of three macros.

Let me know if you need any other explanation or help.
Q-28227698.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GeekamoAuthor Commented:
Thank you very much!

~ Geekamo
0
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.