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. Hi All,
    when i always open my userform my background excel are disabled to do multitasking work.
    please suggest me…

  2. I have managed to close my workbook and opened just the userform whenever I click on the workbook, but I cant get back into the VBA editor and change the form whenever I want to make adjustments. Every time I close the userform it doesn’t open the editor or workbook. Any ideas??

  3. If you don’t know what you called it, more than likely userform1. Check by clicking on the developer tab, click the editor button, and it should show you a project window with all items associated with worksheet. Click on associated user forms to confirm.

  4. hi everybody,
    I want to create a Combobox with the name of every sheet of my workbook in it and when value is chosen in the combobox it will bring up a next Userform according to the sheetname.In the new userform what opens i want create a preview print button of that sheet and a go back button to the first userform. Can somebody help me with the codes to create this?? Im new to writing codes but this will help me alot.

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.