[英]Excel VBA: Workbook_Open
我正在使用 Workbook_Open 在打开应用程序时调用用户表单,这工作正常。 但是我希望它只在第一次打开时运行。 我试过这个,如果我从编辑器运行 sub ,它会工作,但当我打开文件时不会。
Sub Workbook_Open()
If Worksheets("DataSheet").Range("A1").Value = "" Then
QuickStartForum.Show
End If
End Sub
注意:A1 包含一个将在用户表单运行后填充的值
问题似乎在于它在将数据加载到工作表之前打开了用户表单。
有没有办法解决这个问题,还是我需要采取不同的方法?
我认为这是因为您在Module
有此代码。 您需要将代码放在“ ThisWorkBook
”中。
我尝试了以下代码,当它在' ThisWorkBook
'中时没有问题,它无法在' Module1
'中运行
Private Sub Workbook_Open()
If Worksheets("DataSheet").Range("A1").Value = "" Then
QuickStartForum.Show
Worksheets("DataSheet").Range("A1").Value = "filled" ' <-- this fills the cell with data for testing, so that when you reopen the file it should not re-open the userform
Else
MsgBox ("not shown because the A1 cell has data")
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.