+ Reply to Thread
Results 1 to 9 of 9

VBA Select which macro to run, all in one macro.

  1. #1
    Registered User
    Join Date
    12-27-2016
    Location
    Switzerland
    MS-Off Ver
    2010, Office 365
    Posts
    26

    Question VBA Select which macro to run, all in one macro.

    Hi, im new to VBA. How can I do a popup, which asks what macro i want to run. I want the two possibilities in 1 macro like this:

    Sub Test()

    blabla

    If user selects macro 1, Do this code:
    blabla

    If user selects macro 2, Do this code:
    blahblah

    End Sub
    Last edited by stupsi01; 01-04-2017 at 06:39 AM. Reason: Solved

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA Select which macro to run, all in one macro.

    Something like

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: VBA Select which macro to run, all in one macro.

    Hi!
    Lets say you have two sub routines:

    Please Login or Register  to view this content.
    Now you need to run one of them:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-27-2016
    Location
    Switzerland
    MS-Off Ver
    2010, Office 365
    Posts
    26

    Re: VBA Select which macro to run, all in one macro.

    @kasan
    Thanks, that worked. How can I change vbYesNo to a specific text such as Macro 1, Macro 2?
    Last edited by stupsi01; 01-03-2017 at 11:22 AM.

  5. #5
    Registered User
    Join Date
    12-27-2016
    Location
    Switzerland
    MS-Off Ver
    2010, Office 365
    Posts
    26

    Re: VBA Select which macro to run, all in one macro.

    @mikerickson
    Hi, thanks that worked. Can I do that with just one "text" in the field? Like so:

    What macro do you want to start?

    Macro1 Macro2

  6. #6
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: VBA Select which macro to run, all in one macro.

    @stupsi01
    MsgBox is simple, build-in solution. And its standart.
    In case you want buttons named Macro1 and Macro2 - userform shold be used. Userform will allow you to make many buttons and name them as you wish.

  7. #7
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: VBA Select which macro to run, all in one macro.

    Here is simple example of two custom buttons.
    Attached Files Attached Files
    Last edited by kasan; 01-03-2017 at 03:58 PM.

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA Select which macro to run, all in one macro.

    Quote Originally Posted by stupsi01 View Post
    @mikerickson
    Hi, thanks that worked. Can I do that with just one "text" in the field? Like so:

    What macro do you want to start?

    Macro1 Macro2
    No, the captions of a MsgBox are fixed and cannot be customized.

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: VBA Select which macro to run, all in one macro.

    Hi,

    You can use InputBox rather then MsgBox. You might also use Application.Run if they will be entering the name of a macro to run.

    It is in fact possible to alter the captions of the MsgBox buttons but it requires API callbacks.
    Last edited by xlnitwit; 01-04-2017 at 02:55 AM.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 01-07-2015, 12:19 PM
  2. macro to select free cell at end of row and run another macro.
    By wynn1964 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2014, 01:05 PM
  3. [SOLVED] Macro that prompts user to select a file to open and perform another macro on this file
    By grimmy26 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-16-2014, 08:39 AM
  4. Stop Macro, Select Cell, Restart Macro
    By tenk283 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2010, 12:48 AM
  5. Pause macro, select file, continue macro
    By DamienC in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-18-2008, 07:18 AM
  6. Macro to select certain sheets then perform part of other macro on them only
    By raehippychick in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-05-2007, 10:12 AM
  7. Select a macro button with a macro
    By Spike in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-20-2006, 07:35 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1