Show UserForm When Excel File Opens

Show UserForm When Excel File Opens

To help users enter data in a workbook, you can create an Excel UserForm, with text boxes and combo boxes. Then, with a quick bit of code, you can show UserForm when Excel file opens, so the form is easy to find and use.

Parts Inventory Data Entry Form

Here is the parts inventory data entry form from the sample file.

Show UserForm When Excel File Opens

In the original UserForm sample file, there was a button on the worksheet, and users could click it to open the UserForm.

userformstart01

Open the UserForm Automatically

In some workbooks, you might want people to get right to work, and see the UserForm immediately.

So, instead of putting a button on the worksheet, for people to click, you can show the UserForm automatically, when the file opens.

Code to Open the Form Automatically

To make the UserForm open automatically, you’ll add a bit of code to the workbook’s code module, in the Workbook_Open procedure.

To add the code:

  • In the UserForm workbook, press Alt + F11, to open the Visual Basic Editor.
  • At the left, in the Project Explorer, find the UserForm workbook, and double-click on its ThisWorkbook module (in the Microsoft Excel Objects folder).

userformstart02

  • At the top left of the main code window, from the Object drop down, select Workbook

userformstart03

  • At the top right, from the Procedure drop down, select Open
  • The Workbook_Open procedure will be automatically created, with the cursor positioned between the first and last lines of code.

userformstart04

  • Where the cursor is flashing, type a line that opens the UserForm. In this example, the UserForm is named frmParts, so type the following line of code in the Workbook_Open event:
    • frmParts.Show

userformstart05

Test the Workbook_Open Code

To test the Workbook_Open code, follow these steps:

  • Save and close the UserForm workbook.
  • Open the workbook, and enable macros, if prompted.
  • The UserForm will open automatically.

______

32 thoughts on “Show UserForm When Excel File Opens”

  1. 3 Tables are in a workbook, one on each differently names tab, e.g. Tab A, B, C.
    When workbook is opened the built in “data entry form” shows for Tab A
    Cannot figure out VBA code to add so that when Tab B is selected or Tab C is selected – the
    “data entry form” for that worksheet is displayed.
    Thank you so much!

  2. Hi Morton.. Im not sure how to define to check what Tab is selected.. But maybe try it this way (i did the same in past)
    In some cell that is free to be used, lets say A1, put Tab name into.. I mean like in Tab A, put “A” into A1cell. In Tab B, put “B” into A1cell. In Tab C, put “C” into A1cell.
    lets say you have dataentries called -userformA, userformB, userformC-
    Then define in VBA to check cell A1 value, no matter what sheet is selected.. And based on value correct userform will be showed… Something like this.. (change it to fit your values, ranges and names)
    ……..
    Private Sub Workbook_Open()
    range(“A1”).select
    if selection.value = “A” then
    userformA.show
    else
    GoTo 2
    end if
    2:
    if selection value = “B” then
    userformB.show
    else
    GoTo 3
    end if
    3:
    if selection.value = “C” then
    userformC.show
    else
    exit sub
    end if
    end sub

  3. I am new to coding. I am following your instructions to open my form automatically. The form’s name is UserForm1, which I am adding the ca\ode as follows.
    Private Sub Workbook_Open()
    frmUserForm1.Show
    End Sub
    Keeps asking for a variable, not sure what that is. Any help would be greatly appreciated.

  4. John,
    I have a module inserted into a combo box to show options for users to choose. I can get the form to auto open, but the module won’t populate the combo box. I am using excel 2011 for Mac. The module is called ‘module 1’. Any ideas?

  5. Sean:
    I took my list that I was using for the combo box and created dynamic name ranges. Under formulas you can click on Define names and create this. I also copied the data I am using and in the upper left hand corner of the spreadsheet you will see it is labeled as A1, change this to something easier like DEPARTMENTS so you will know what it is. Go to your combo box, click in the field and click on properties. Look on the left hand side for RowSource, enter the name you gave your dynamic range, mine is DEPARTMENTS. This should allow the range to populate to the combo box.
    Good Luck
    john

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.