2

I am using :

Private Sub start_Click() UserForm1.Show End Sub 

To open my user interface by pushing the start button. But, I would like my user interface to be opened automatically in the very beginning when I have just opened my excel file. Does anyone know how I can do that?

1
  • put your code into the Workbook_Open sub Commented May 19, 2016 at 19:48

3 Answers 3

2

In the Workbook code pane type this

Private Sub Workbook_Open() UserForm1.Show End Sub 
Sign up to request clarification or add additional context in comments.

Comments

0

Create a subroutine in your workbook named Workbook_Open

Private Sub Workbook_Open() MsgBox "yo!" End Sub 

You can call other functions/subs from here.

Comments

0

The ThisWorkbook module is a class module that implements the WorkbookEvents interface, which means you get to select what looks like a hidden Workbook field in the left code pane dropdown:

Workbook object

As if ThisWorkbook had this code implicitly written for you:

Private WithEvents Workbook As Excel.Workbook 

Selecting Workbook from the left dropdown will fill up the right dropdown with all events available in a Workbook object:

workbook events

When you pick an event in there, the VBE generates a stub event handler procedure for you, or navigates to it if it already exists.

Typing the event handler signature by hand will also work, but for the more complex signatures that take parameters of specific types in a specific order, it's simpler to have the VBE generate the stub for you - automatically generated handlers will always have the correct signature!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.