用户表单未触发初始化或激活事件

编程入门 行业动态 更新时间:2024-10-26 11:21:24
本文介绍了用户表单未触发初始化或激活事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在工作表中保留了一个用户窗体控制按钮以启动一个宏,该宏又显示一个用户窗体,在该窗体中,我希望在复选框中显示打开的文件(使用Workbooks集合).我希望运行一个宏,仅对用户选择的文件执行操作.

I kept a userform control button in my worksheet to fire up a macro, which in turn shows a user form, In the form I wish to display the opened files in checkboxes(using the Workbooks collection).I wish to run a macro that performs action for the user selected files only.

因此,对于工作表中的按钮,我分配了以下宏

So for the button in my worksheet, I have assigned the following macro

Private Sub Button2_Click() Load MyForm MyForm.Show End Sub

首先我将下面的代码保存在宏子模块所在的模块中,由于它不起作用,所以我右键单击用户窗体并选择了视图代码,并将下面的代码保留在那里,但仍显示相同的静态设计用户窗体,而不是动态窗体.我在加载Myform和MYform.Show()时都保持断点,并逐步执行了代码.它从来没有进入初始化或激活方法.

At first I kept the below code in the module where my macro sub is there.Since it's not working, I right clicked on user form and selected view code and kept the below code there.But still it's showing the same static designed user form, not the dynamic.I kept breakpoint at both load Myform and MYform.Show() and I stepped through code.It never went into intialize or activate method at all.

Private Sub MyForm_Activate() 'for checking the whether this method is called or not I am trying to change caption MyForm.LabelSelectFile.Caption = "dhfdfldkfldzjf;zdfkz;d" Dim mymyWorkBook As Workbook For Each mymyWorkBook In Workbooks 'code for creating checkbox based on the file name displayed by the workbook collection Next mymyWorkBook End Sub

我不明白为什么未触发该事件.请帮助我解决此问题.谢谢!

I can't understand why that event is not getting triggered.Please help me to overcome this.Thanks in advance

推荐答案

即使表单名称为MyForm,您仍需要使用userform.

Even though the name of the form is MyForm, you still need to use userform.

'~~> in your worksheet Private Sub Button2_Click() MyForm.Show End Sub '~~> In the userform code area Private Sub UserForm_Initialize() '~~> Your code here End Sub

Private Sub UserForm_Activate() End Sub

最好是始终从下拉列表中选择事件,而不是键入事件

The best is to always select the event from the drop down, rather than typing it

更多推荐

用户表单未触发初始化或激活事件

本文发布于:2023-11-04 01:22:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556559.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   初始化   事件   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!