Excel VBA Forms

You can create Excel VBA forms (Excel VBA userforms) in the VBA editor which you display while the workbook is open. To start, open the editor, right click on Microsoft Excel Objects in the VBAProject Explorer at the upper right. choose Insert Userform.

Excel VBA Forms 1 - Insert Excel VBA Form


Now add a textbox by clicking on the AB| control in the toolbox that appeared when you inserted the form. Also, in the same way, add a Command Button.

 
Excel VBA Forms 2 - Add Controls to the Form


(Click the arrow control at the upper left of the Toolbox to return the mouse pointer if the mouse is trying to draw a control.)

Double click the Command Button to open the code editor with an empty Sub routine for the button and add the line Userform1.Hide , this wll close the form

Private Sub CommandButton1_Click()
    UserForm1.Hide
End Sub

To open your the form, double click on ThisWorkbook in the VBAProject Explorer and then choose Workbook at the upper left of the code window.

Excel VBA Forms 3 - Open Excel VBA Form


The Workbook methods now appear to the right and the default "Open should have been selected. Add the line UserForm1.Show . This will display the form when the workbook is opened.Private Sub Workbook_Open()
    UserForm1.Show
End Sub

Save and close the workbook then reopen. The form appears. Clicking the button now closes the form.

You can create more userforms and use Command Buttons to open them.

This site is powered by Site Build It!. If you enjoy it, please check out the
Site Build It homepage
 to learn more and on how to build a success-guaranteed site with no technical skills.





Return from Excel VBA Forms to VBA Code Samples

Return to our Homepage