VBA - Create ListBox -To List & Run Macros RRS feed

  • Question

  • Hi Friends,

    hope all are well.

    I am trying to make a list box to list the macros found in word.

    In word we have the macrobox that lists all the macros.

    I do have a big problem with the current macro box because the font is sooooo tiny and i spend ages looking for the macro and then clicking the wrong one,and well it's a bit of a problem for me.

    And well my eyes are not very good with it.

    I tried using windows magnifier but that causes more problems for me.

    So I was trying to emulate the macro box so that I could make the font bigger to see.

    I will list the macros in a  userform listbox.

    Option Explicit
    Private Sub UserForm_Initialize()
    Dim VBProj As VBIDE.VBProject
        Dim VBComp As VBIDE.VBComponent
        Set VBProj = ActiveDocument.VBProject
        For Each VBComp In ActiveDocument.VBProject.VBComponents
            If VBComp.Type = vbext_ct_StdModule Then
             VBComp.AddItem (VBComp.Name)
        Next VBComp
    End Sub
    Private Sub CommandButton1_Click()
    Dim i As Integer
    'oMacro VBComp As VBIDE.VBComponent
        For i = 0 To MacroBox.ListCount - 1
            If MacroBox.Selected(i) = True Then
                Application Run = MacroBox.list(i)
            End If
        Next i
    End Sub

    I have added my file here.

    I am not sure if this is possible so I thought I would try and ask

    If any one can lend any ideas on how I may be able to do this

    Cheers Dan

    • Edited by Dan_CS Monday, July 18, 2016 7:10 PM Spelling
    Monday, July 18, 2016 7:10 PM

All replies

  • Your code certainly does not do what you intend and in any case there are better approaches. The one I favour  is to create a simple ribbon that calls the macros I use regularly -   

    Graham Mayor - Word MVP

    Tuesday, July 19, 2016 8:44 AM
  • Hello Graham,

    thank you for this tip.

    I will investigate this - I did try the ribbon once and well - the macros kept changing and it would not work when i changed the name.

    I wish word would create a bigger box for us  - who can't see those small names - it is so tiny.Is there an easy

    Is there a way for me to get all my macros into a ribbon without hard coding each one?

    There's a lot of mini macros and well- each time i have to add a new one may mess up my ribbons

    Cheers Dan

    Tuesday, July 19, 2016 2:37 PM