问题
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:
In the Workbook code pane type this
Private Sub Workbook_Open()
UserForm1.Show
End Sub
回答2:
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.
回答3:
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:
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:
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!
来源:https://stackoverflow.com/questions/37332604/how-to-open-user-interface-with-opening-the-file