VBA function to open a form (UserForm) in Microsoft Office

VBA - Visual Basic for Application

If you want to simplify your daily work with VBA scripts, you can also create one or the other form (UserForm) to process user input and user interactions.

screenshot open UserForm in Excel via button and macro
Example open form with multiline textbox via button in Excel spreadsheet

If you want to start such a UserForm, e.g. with multiline textbox, from an Excel, Word or Microsoft Office application, you have to use the correct function.

DoCmd.OpenForm does not work

Because in the Internet it is often recommended to open a created form with the code.

DoCmd.OpenForm "MyUserFormName"

But this is apparently only meant for Access and brings a debug error with Excel, Word and Co.

VBA code to display the UserForm

If you want to display a previously created form via an Excel macro or Word macro, you have to use the routine Show. To do this, one uses the form name and calls the Show method.


So you can then include this line of code in a Macro Sub and link the button to the macro to display the form.

Screenshot VBA editor with UserForm.Show statement to open a form
Example Open form via button in Excel spreadsheet

Leave a Reply

Your email address will not be published. Required fields are marked *