首页 > 解决方案 > 重新打开功能后,我怎样才能让它再次启动我的用户表单?

问题描述

因此,此功能将有效地重新启动我的工作簿,但是,我设置为在工作簿打开时打开的用户表单并没有被踢出,我不确定为什么。我不知道它是否绕过了该功能或什么...

Private Sub CommandButton3_Click()

Dim sPath As String
Dim sName As String
sName = ThisWorkbook.Name
sPath = ThisWorkbook.Path
ThisWorkbook.Saved = True
Workbooks.Open Filename:=sPath & "\" & sName

''''at a minimum I need this userform to show and it wont when i run this funtion.
UserForm1.Show

End Sub

标签: excelvbauserformself-executing-function

解决方案


您无法打开已激活的同一文件。所以你需要先关闭它才能再次打开它。它破坏了你的代码。所以它不会工作。你需要关闭它。

如果您想让您的用户窗体在开始时弹出,只需将我的代码放入 Workbook_Open,每次启动文件时都会打开它。

Private Sub CommandButton3_Click()
'Vbmodal ensures that user need to interact with userform or discard it to select cells etc.
UserForm1.Show vbmodal

End Sub

推荐阅读