Outlook 中的用户窗体没有响应(无法关闭,按钮单击事件不触发)

发布于 2024-07-21 06:04:00 字数 375 浏览 9 评论 0原文

我在 Outlook VBA 宏中创建了一个简单的 UserForm - 我可以使用以下代码使表单可见:

VBA.UserForms.Add (PasswordForm.Name)
PasswordForm.Show (Modal)

...并且 UserForm_Initialize() 事件实际上会触发。 但是单击表单上的“提交”按钮不会执行任何操作 - SubmitButton_Click() 事件(通过双击设计器中的按钮自动创建)永远不会触发。 此外,用户窗体在窗口的右上角有一个通常的红色小 X,但单击它不会执行任何操作(窗体不会关闭或退出)。

知道我可能做错了什么吗? 我对 VBA 还很陌生。

I've created a simple UserForm in my Outlook VBA macro - I can make the form visible using this code:

VBA.UserForms.Add (PasswordForm.Name)
PasswordForm.Show (Modal)

...and the UserForm_Initialize() Event does in fact fire. But clicking on the "Submit" button on the form does nothing - the SubmitButton_Click() Event (which was auto-created by double clicking on the button in the designer) never fires. Also, the userform has the usual little red X in the top right corner of the window, but clicking this doesn't do anything (the form doesn't close or exit).

Any idea what I might be doing wrong? I'm quite new to VBA.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤云独去闲 2024-07-28 06:04:01

有时,VBA 中的控件会与其事件分离。 这可能是因为您重命名了控件,或者因为您不小心重命名了事件过程(尽管由于其他原因很少会发生这种情况)。 另外,如果您忘记在运行表单之前“编译”,则表单上可能存在导致问题的错误。

仔细检查的最简单方法是在设计视图中打开表单,选择有问题的按钮并按 F7。 如果创建了新过程,请复制粘贴您的代码,然后将旧代码复制/粘贴到其中,然后删除旧代码。

完成后,转到“调试”菜单并单击“编译”。 如果检测到任何错误,请更正它们并再次单击“编译”。 重复直到编译无怨言。 然后尝试再次运行您的表单。

Sometimes controls in VBA get decoupled from their events. It can be because you renamed the control or because you accidentally renamed the event procedure (although it rarely can happen for other reasons). Also, ff you have forgotten to "compile" before running the form, you may have an error on the form that is causing the issue.

The easiest way to double check is to open the form in design view, select the button in question and press F7. If a new procedure is created, copy an paste your code then just copy/paste your old code into it, and get rid of the old one.

After you have done that, go to the "Debug" menu and click "compile". If any errors are detected, correct them an click "Compile" again. Repeat until it compiles without complaint. Then try running your form again.

奈何桥上唱咆哮 2024-07-28 06:04:01

好的,解决了:我改变了:

PasswordForm.Show (Modal)

现在

PasswordForm.Show

它可以工作了,尽管我必须稍微改变它的工作方式以适应表单不再是模态的事实(我认为无论如何这是更好的解决方案,模态可能会让用户烦恼,只是我现在必须检查他们是否提交了表单等)。

感谢大家的建议。

OK, solved: I changed:

PasswordForm.Show (Modal)

to

PasswordForm.Show

and it now works, although I'll have to change the way it works a bit to accommodate the fact that the form won't be modal any more (I suppose it's the better solution anyway, modals can be annoying to the user, it's just I have to check that they submitted the form, etc now).

Thanks all for your suggestions.

孤蝉 2024-07-28 06:04:01

在 Office 03/07 中,如果要确保它显示模式,请将表单的 .ShowModal 行为设置为“True”。 我在尝试在演出活动期间使表单模态化时遇到了问题。

In Office 03/07, if you want to make sure it shows modal, set the form's .ShowModal behavior to "True". I've had issues with trying to make the form modal during the show event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文