logo
Home
FREE DOWNLOADS
VBA Tutorials
VBA Code Samples
VBA Code - Excel
VBA for Beginners
Save Time on PC
SaveTimeWebsite
Save Time News
Save Time Blog
SaveTime SiteMap
Customer Service
Gibberish

Subscribe To
This Site

XML RSS
Add to Google
Add to My Yahoo!
Add to My MSN
Add to Newsgator
Subscribe with Bloglines


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.

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.


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 Excel VBA form, double click on ThisWorkbook in the VBAProject Explorer and then choose Workbook at the upper left of the code window.

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.

.





Return from Excel VBA Forms to VBA Code Samples


Return to our Homepage


footer for Save Time page