Results 1 to 5 of 5
  1. #1
    Azri1
    Guest

    chhose comboxes from userform to run macros..

    I'm lookingfor a box to appear so I can
    can select and run a macro? Hopefully it will
    be combo boxes so I can run a few macros
    simulataneously..Is is possible? Thanks

    ps: maybe it it userform that been attached by
    combo boxes..hope you can write down the full code to
    run it coz i'm very new to vb

  2. #2
    Azri1
    Guest

    Re: chhose comboxes from userform to run macros..

    To make it clearly..what I meant is when I run a macro
    from a button, a userform will popup. A combo boxes
    that attached to the userform will can make me to choose
    a few macros to run..maybe 4 macros simultaneously..
    Is it possible guys..Many thanks to you all

  3. #3
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Kortrijk, Belgium
    Posts
    571
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: chhose comboxes from userform to run macros..

    You can do something like this: Add a userform (which I called ListBoxFrm) to your vbaproject and add a listbox (called ListBox1) (or combobox) to the form, together with an "OK" (CmdOK) and a "Cancel" (CmdCancel) commandbutton.
    Add the following code to the userform:

    Private Sub CmdCancel_Click()
    Me.Hide
    End Sub

    Private Sub cmdOK_Click()
    Dim StChoice As String
    StChoice = ListBox1.Value
    Me.Hide
    If StChoice = "Macro1" Then SubMacro1
    If StChoice = "Macro2" Then SubMacro2
    If StChoice = "Macro3" Then SubMacro3
    End Sub

    Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    cmdOK_Click
    End Sub

    Private Sub UserForm_Activate()
    ListBox1.Clear
    ListBox1.AddItem "Macro1"
    ListBox1.AddItem "Macro2"
    ListBox1.AddItem "Macro2"
    End Sub

    Of course, you still need a Module from which you have to start up your userform. Add the following code to that module

    Sub LaunchListBoxFrm()
    ListBoxFrm.Show
    End Sub

    In this module you can add the code for your macros:

    Sub SubMacro1()
    ....
    End Sub

    etc...

  4. #4
    Azri1
    Guest

    Re: chhose comboxes from userform to run macros..

    thanks for the response Hans..but I still need your help.
    I'm just a newby to vba..so..if you have spare time and
    not bother you..could you give me an example workbook
    describing how to do this difficult operation to me..coz
    i don't have a clue at all..Please Hans.hope you willing
    to help me again.

  5. #5
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Kortrijk, Belgium
    Posts
    571
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: chhose comboxes from userform to run macros..

    OK, I'll try to explain this:
    1) go to the VBE (Visual Basic Editor), via Tools >> Macro >> Visual Basic editor
    2) try to find the active workbook in the Project explorer (the name of the workbook should be mentioned with VBAproject next to it. If the Project explorer is not visible, make it visible via View >> Project Explorer
    3) Add a userform to the VBAproject, by choosing Insert >> Userform
    4) Add a module to the VBAProject by choosing Insert >> Module
    5) Choose the userform you added by double clicking it in the VBAproject. The Toolbox should be preset as well. Add a listbox, and two commandbuttons to the userform by dragging and clicking
    6) Make the Properties window visible via View >> Properties (or something like that)
    7) Select one commandbutton and go to the properties window to change its name and caption. Do the same for the other commandbutton.
    8) Proceed as given in my previous post.

    Hope this helps you going in the right direction.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •