Application.OnTime不适用于用户窗体 [英] Application.OnTime doesn't work with userform

查看:91
本文介绍了Application.OnTime不适用于用户窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一段代码有问题:

Private Sub cyclic()

Static i As Integer
i = i + 1

Cells(i, 11) = i
Open source For Append As #1
Write #1, Cells(i, 11)
Close #1

Application.Wait (Now + TimeValue("0:00:01"))

Open source For Input As #1
Do While Not EOF(1)
Input #1, x1
Loop
Cells(i, 1) = x1
Close #1

Application.OnTime Now + TimeValue("00:00:03"), "cyclic"

End Sub

非常像这样. 从工作表alt + f8宏的级别来看,它可以完美地工作,但是当我想通过单击CommandButton来与Userform一起使用它时,它不会以4秒的间隔周期性地发生,而是仅执行一次循环.如果我想用数字填充更多的单元格,则必须单击单击单击单击,然后单击该死的按钮.我希望它更自动.

It's pretty much like this. It works perfectly from the level of worksheets alt+f8 macros, but when I want to make use of it with a Userform just by clicking a CommandButton it doesn't happen periodicaly with a 4 seconds interval, but do only one loop. If I want to fill more cells with my numbers I have to click click click and click the damn button. I wish it was more automatic.

这是我用来调用循环函数的用户窗体"按钮中的一段代码.它应该重复,但不是.

Here is a piece of code from Userform button I am using to call the cyclic function. It should be repeating, but it's not.

Private Sub cbCyclic_Click()
cyclic
End Sub

我在做什么错了?

推荐答案

Application.OnTime引用的过程必须驻留在标准代码模块中.它不能位于类模块中,并且用户窗体是专门的类.

A procedure referenced from Application.OnTime must reside in a standard code module. It cannot be located in a class module, and userforms are specialized classes.

在标准代码模块中调用的过程必须是公共的.

The procedure being called in the standard code module must be Public.

您最好的选择是将cyclic()定位到标准代码模块并将其公开.然后,您无需更改用户表单中的命令按钮单击事件过程即可.

Your best bet is to relocate cyclic() to a standard code module and make it Public. Your command button click event procedure in the userform should then work with no alteration.

这篇关于Application.OnTime不适用于用户窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆