none
Open UserForm from Ribbon Button RRS feed

  • Question

  • Hello,

    I have created a custom Ribbon with several custom buttons.

    How can I open a user form when a button on the Ribbon is clicked?

    Specifically what should the button's OnAction = ?

    Thanks,

    M. Wilson


    M. Wilson

    Wednesday, April 19, 2017 6:49 PM

All replies

  • Create a sub like the following in a standard module.

    Sub OpenForm()
        UserForm1.Show
    End Sub

    Then the button's OnAction = "OpenForm"

    If the workbook is not already open then try following:

    OnAction = "'C:\Users\UserName\Documents\Excel\Test Macros\Button to open userform'!OpenForm"

    Note that the path and filename is enclosed in single quotes and then the entire path and workbook name enclosed in double quotes.


    Regards, OssieMac


    • Edited by OssieMac Thursday, April 20, 2017 6:02 AM Add if workbook not already open
    • Proposed as answer by Chenchen LiModerator Thursday, May 4, 2017 9:09 AM
    Thursday, April 20, 2017 5:50 AM
  • Hello,
    I think you are customizing the ribbon via VBA, so the callback for the button should be

    Sub OpenForm(control As IRibbonControl)
    UserForm1.Show
    End Sub
    

    To determin correct signatures for each callback, please visit Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, April 25, 2017 8:15 AM
    Moderator