用户窗体打开时打开

时间:2015-05-22 04:12:02

标签: excel vba excel-vba

有点卡住VBA,我试图让我的用户形式“ParcelDataEntry”打开,当我从我的首页上选择一张表格时,我在我的首页上有这样的选项,当我越过这个障碍时。

所有54个工作表都包含以下代码:

Private Sub Worksheet_Open()
    ParcelDataEntry.Show
End Sub

1 个答案:

答案 0 :(得分:1)

我认为没有Worksheet_Open事件。而是使用Workbook_SheetActivate事件。您应该将此代码放在ThisWorkbook代码模块中。

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Call OpenDataEntryForm
End Sub

将您的userform视为对象,并相应地声明和实例化它。

Public Sub OpenDataEntryForm()

Dim dataEntryForm As ParcelDataEntry

' Create an instance of the form
Set dataEntryForm = New ParcelDataEntry
' Show the form
dataEntryForm.Show
' Do something here

' If the form was opened as Modal, then the code here will only run
' once the form has been hidden/closed
' Now destroy the object
Set dataEntryForm = Nothing

End Sub