How to open user interface with opening the file

旧街凉风 提交于 2021-02-05 07:47:06

问题


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:

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!



来源:https://stackoverflow.com/questions/37332604/how-to-open-user-interface-with-opening-the-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!