有人知道是否可能,或者对我如何允许用户更新现有私有子代码的某些部分有任何想法吗?
例如:
当前:UserForm_Initialize Textbox1="测试">
用户更新后:UserForm_Initialize TextBox1="你好">
假设您下次需要打开表单来显示TextBox1
中使用的最后一个文本,请使用下一种方法:
- 复制表单代码顶部的下一个声明(在声明区域(:
Option Explicit
'It is good to use relevant constants, able to better reflect their meaning:
Private Const MyApp As String = "MyApplication"
Private Const Sett As String = "Settings"
Private Const Txt1 As String = "Txt1Val"
- 将此代码放入TextBox1
Change
事件中:
Private Sub TextBox1_Change()
SaveSetting MyApp, Sett, Txt1, TextBox1.Text
End Sub
- 复制
Userform_Initialize
事件中的下一个代码:
Dim Txt1Val As String
Txt1Val = GetSetting(MyApp, Sett, Txt1, "No value")
If Not Txt1Val = "No value" Then Me.TextBox2.Text = Txt1Val
现在,当用户更改TextBox1
文本时,新字符串将存储在注册表中,并用于在下一次UserForm初始化期间加载。。。
如果有什么不清楚的地方,请毫不犹豫地询问。