Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically open a user form in excel 1

Status
Not open for further replies.

varajan

Technical User
Oct 5, 2001
42
0
0
IN
I have a form defined using VBA in Excel. This form needs to be displayed as soon as the excel worksheet is opened. How is this possible ?
 
Open the VBA editor (Alt-F11)
Find your project in the Project Explorer (if the Project Explorer is not showing, show it by keying Ctrl-R)
Find the node that says "ThisWorkbook" and right-click on it.
Select "View Code"
Select "Workbook" from the left-hand combo box at the top of the work area.
You should see code like this
Code:
Private Sub Workbook_Open()

End Sub
Add a line of code to complete the macro like this:
Code:
Private Sub Workbook_Open()
  UserForm1.Show
End Sub
Save the workbook and you're done.

 
Many thanks Zathras.

Wondering if you can help me a bit further.

Now, the form is displayed, but the excel sheet appears in the background.

1. Can I hide the excel sheet somehow ?
OR
2. Can I have only this form running (something like an .exe) with spreadsheet not being displayed.

3. I have an exit button - How do I exit the application itself.
 
You could add a line to the first macro to make it look like this:
Code:
Private Sub Workbook_Open()
  ActiveWindow.WindowState = xlMinimized
  UserForm1.Show
End Sub
And you can put this code as the action for the command button (double-click on the button to open the appropriate code page):
Code:
Private Sub CommandButton1_Click()
  Application.Quit
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top