+ Reply to Thread
Results 1 to 2 of 2

UserForm and calling different macros

  1. #1
    Registered User
    Join Date
    11-10-2015
    Location
    Adelaide,Australia
    MS-Off Ver
    Windows7
    Posts
    1

    UserForm and calling different macros

    Hello
    I have created an excel workbook with a number of worksheets. I have also created a userform1 from excel developer where all the worksheets are visible in a menu, each worksheet has a checkbox against it, each worksheet has a separate small macro. When a user opens the workbook they are presented with this menu, the idea is when the worksheet is selected in the menu it will run the macro associated with that worksheet but how do I call the macro when the worksheet is selected in the menu.
    • The user is presented with the menu
    • The user will physically go the tab in the worksheet and fill in some data, there may be more than one worksheet to update.
    • The user returns to the menu I created and selects the worksheets which will run the macro, each worksheet has a different macro but I have managed to get them working just need help on the calling them from the menu(userform) part. I thought about going to each worksheet and placing a macro button on it and assigning it to the macro however I think this would look professional.
    This code behind the userform is below, it allows me to select the sheet but having problems calling the associated macro once the sheet is selected

    Any help will be appreciated

    Sub OKButton_Click()
    Dim i As Integer, MaxItem As Integer
    Dim outputstring As String
    Dim itemselected As Boolean

    MaxItem = Me.SheetSelector.ListCount - 1

    With Me.SheetSelector
    For i = 0 To MaxItem
    itemselected = .Selected(i)
    If ((Me.IncludeSelected And itemselected) Or Me.IncludeAll) Then
    outputstring = outputstring & "," & Me.SheetSelector.List(i)
    ElseIf (Me.ExcludeSelected And (Not itemselected)) Then
    outputstring = outputstring & "," & Me.SheetSelector.List(i)
    End If
    Next
    End With
    MsgBox Mid(outputstring, 2)
    End Sub

    Sub UserForm_Initialize()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    Me.SheetSelector.AddItem ws.Name
    Next
    Me.IncludeSelected = True
    End Sub

  2. #2
    Forum Contributor mongoose36's Avatar
    Join Date
    06-10-2013
    Location
    Lincoln
    MS-Off Ver
    Excel 2013
    Posts
    389

    Re: UserForm and calling different macros

    Dinamo, welcome to the excel forum!!

    You should be able to call the macro directly in the OKButton_Click event by name. For example if you have created another macro named
    Please Login or Register  to view this content.
    Then when you wish to call that particular sub just type the name
    Please Login or Register  to view this content.
    Hopefully that makes sense...also in future posts please try to use code tags (the hash tag in the WYSIWYG) around all your code to help differentiate it from normal text. See rule 3 of the forum rules

    Best of luck!
    If your questions has been answered to your satisfaction please don't forget to do the following:

    Add Reputation ... and ... Mark Thread as Solved

    Thanks,

    Ma 10:8b Freely you have received; freely give.

+ 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] Calling Macros from a Macro
    By Strup in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-11-2013, 04:46 AM
  2. Calling Macros
    By RBI in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2008, 10:22 AM
  3. Calling Macros
    By arvind68 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2007, 10:31 AM
  4. Functions and macros - calling a UDF
    By elprup in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-03-2006, 09:59 AM
  5. [SOLVED] Calling macros in another workbook
    By Nick Wright in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-12-2006, 12:10 PM
  6. [SOLVED] Trouble calling Add-In Macros
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-15-2005, 07:05 AM
  7. Problems calling macros in addin from within macros
    By Andibevan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2005, 05:05 AM
  8. [SOLVED] Calling Excel 4 Macros From VBA
    By Eloy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2005, 01:06 PM

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