+ Reply to Thread
Results 1 to 3 of 3

Executing a Macro with Variable Name from String

Hybrid View

  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    Canberra, Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    Exclamation Executing a Macro with Variable Name from String

    Hi Again Team,

    I'm trying to execute a macro based on the value of a string.

    Does anyone know how this could be done?

    I have this so far:

    ' Function to open the correct UserForm.
    Sub OpenUserForm(UserFormName As Variant, UserFormAction As Variant)
    '   Prepare the UserForm
        MacroName = "PrepareForm" & UserFormAction
        MacroName (UserFormName)
    '   Show the UserForm
        VBA.UserForms.Add(UserFormName).Show
    End Sub
    Last edited by zeuscartwright; 08-22-2013 at 01:45 AM. Reason: Sovled

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: Executing a Macro with Variable Name from String

    Application.Run macroname, userformname
    should work, although I'm not sure what your macro would do that didn't involve loading the form, which you then do again.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    08-21-2013
    Location
    Canberra, Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Executing a Macro with Variable Name from String

    Thanks for that Rory,

    It either preloads the form with data or opens it as a fresh one.

    Also changes some titles here and there depending on why the form is being opened.

    For example, adding a new user or updating an existing users details.

+ 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. [SOLVED] insert variable string in email macro
    By ag273n in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2013, 06:47 PM
  2. Replies: 4
    Last Post: 07-12-2013, 12:14 PM
  3. Macro to open files based on string variable
    By Coeus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2013, 06:47 PM
  4. Transferring a dynamically named string variable to another string variable.
    By Concorde Rules in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-09-2012, 04:08 AM
  5. Passing String Variable from Command Button Macro to a List Box in same User Form
    By wz4np1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2012, 11:31 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