gpt4 book ai didi

vba - Excel VBA : how to cast a control got from the UserForm's Controls collection to its native ActiveX type?

转载 作者:行者123 更新时间:2023-12-04 20:56:09 25 4
gpt4 key购买 nike

我们正在使用第 3 方 ActiveX 网格控件 10Tec iGrid在用户窗体上的 Excel 2016 VBA 应用程序中。我们需要通过动态生成的字符串名称来检索这个控件,并将其转换为它的 native 类型以进行进一步的操作。

对于像 CommandButton 这样的固有 MSForms 类型,这很容易做到,例如:

Dim cmdbtn As iGrid
Set cmdbtn = Me.Controls("cmdOk")

但是,这种方法不适用于 iGrid:

Dim grid As iGrid
Set grid = Me.Controls("iGrid1")

我们总能得到

Type mismatch



错误。

这也无济于事(同样的问题):

Dim grid As iGrid
Set grid = Me.Controls("iGrid1").Object

有没有办法通过 VBA UserForms 中的字符串名称动态获取其 native 类型的 ActiveX 控件?

最佳答案

尝试这个:

Public iGridData As Control
Set iGridData = UserForm1.Controls.Add("iGrid700_10Tec.iGrid", "iGridName", True)

关于vba - Excel VBA : how to cast a control got from the UserForm's Controls collection to its native ActiveX type?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47333186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com