在UserForm中动态生成复选框时出错 [英] Error while dynamically generate a Checkbox in an UserForm

查看:107
本文介绍了在UserForm中动态生成复选框时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个网页上找到了以下代码:

http://www.office-loesung.de/ftopic220336_0_0_asc.php

I found the following code on this webpage:
http://www.office-loesung.de/ftopic220336_0_0_asc.php

Public WithEvents cmdCommandButton As CommandButton
Option Explicit

Dim CommandButtons(15) As clsCommandButtons

Private Sub UserForm_Initialize()
Dim zaehler As Long
For zaehler = 0 To 15
    Set CommandButtons(zaehler) = New clsCommandButtons
    Set CommandButtons(zaehler).cmdCommandButton = Me.Controls(zaehler)
Next
End Sub
Private Sub UserForm_Terminate()
Dim zaehler As Long
For zaehler = 0 To 15
    Set CommandButtons(zaehler) = Nothing
Next
End Sub



首先,我更改了部分代码并且无法正常工作,我收到以下消息:

编译错误:未定义用户定义类型



所以我使用原始代码并再次尝试,我也犯了同样的错误。代码有问题吗?





编辑:

将第一行放入额外的类,名为clsCommandButtons。不幸的是,在网页的文本中并不清楚


First I changed parts of the code and it didn´t work, I got the following Message:
Compile error: User-defined type not defined

So I used the originial code and tried it again and I got the same mistake. Is something wrong with the code?



It works after putting the first line in a extra class, named clsCommandButtons. Unfortunaly it's not clearly in the text of the webpage

推荐答案

很可能你没有复制整个例子。代码在这里使用名为clsCommandButtons的类

Most likely you haven't copied the whole example. The code uses a class named clsCommandButtons over here
Dim CommandButtons(15) As clsCommandButtons



但是如果你没有包含该类的定义在你的项目中,编译将失败。



因此,再次查看源代码并检查定义是否存在。请注意,它可能位于单独的模块中。


But if you haven't included definition for that class in your project, compile will fail.

So have a look at the source code again and check if the definition exists. Note that it may be in a separate module.


这篇关于在UserForm中动态生成复选框时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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