VBA:用户窗体初始化时未命中用户窗体初始化方法

标签 vba module listbox initialization userform

我的模块代码调用用户表单:

PreInfo.Show

我的用户表单代码:
Public Sub PreInfo_Initialize()
Dim Invoice, Name, Model, Crank, MyValue1, StrokeL As Variant
'Dim ListBox1 As ListBox
Dim c As Range
Dim oneControl As Object

'Empty Text Boxes and Set Focus
For Each oneControl In PreInfo.Controls
Select Case TypeName(oneControl)
Case "TextBox"
    oneControl.Text = vbNullString
'Case "ListBox"
    'oneControl.AddItem "Test"
End Select
Next oneControl

With lbTest
    .AddItem Item:="2 Cylinders" '3 different syntax used as test to isolate issue
    .AddItem "3 Cylinders"
    .AddItem ("5 Cylinders")
End With

Invoice.TextBox.SetFocus 'Activate?

End Sub

我的模块代码不会触发我的用户表单初始化子程序,因此该子程序中没有任何内容运行。我无法弄清楚为什么会这样。我将不胜感激任何帮助!

当此代码运行时,会弹出用户窗体,但是没有添加任何列表框项目

最佳答案

我已经想通了。长话短说,我的模块需要以下代码:

Userform.Userform_Activate 'THIS IS THE NEW CODE
Userform.Show 'existing code, unchanged

它指示用户表单在打开之前激活(调用“初始化”,然后显示用户表单供用户更改)。

Userform.Show 应该提示这个激活子运行,但是我的不是出于任何原因。这解决了这个问题,直到我确定为什么 Userform.Userform_Activate 没有像应有的那样被调用。

关于VBA:用户窗体初始化时未命中用户窗体初始化方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16946263/

相关文章:

wpf - 如何在 ItemsControl 上放置标题?

excel - vba - 在循环中调用函数

JavaScript:异步创建实例并在不同模块中使用它

c# - 如何在 Windows 窗体 (C#) 中设置列​​表框的确切高度?

perl - 如何安装 Perl 脚本依赖项?

python-3.x - 即使模块实际上包含脚本,模块也没有属性

jquery - HTML 列表框换行文本

c# - 将长嵌套的 Excel 公式转换为 C#

vba - InSTR 或在 VBA 中查找函数

excel - 将范围设置为值而不重新格式化单元格