简体   繁体   English

Excel VBA:如何将从用户窗体的控件集合中获取的控件转换为其本机ActiveX类型?

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

We are using a 3rd-party ActiveX grid control 10Tec iGrid in an Excel 2016 VBA application on a UserForm. 我们正在UserForm的Excel 2016 VBA应用程序中使用第三方ActiveX网格控件10Tec iGrid We need to retrieve this control by the string name generated dynamically and cast it to its native type for further operations. 我们需要通过动态生成的字符串名称来检索此控件,并将其转换为其本机类型以进行进一步的操作。

This is very easy to do for intrinsic MSForms types like CommandButton, for example: 对于诸如CommandButton之类的固有MSForms类型,这非常容易做到:

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

However, this approach does not work for iGrid: 但是,这种方法不适用于iGrid:

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

We always get the 我们总是得到

Type mismatch 类型不匹配

error. 错误。

This also does not help (the same problem): 这也无济于事(同样的问题):

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

Is there a way to get an ActiveX control in its native type dynamically by its string name in VBA UserForms? 有没有办法通过VBA UserForms中的字符串名称动态获取其本机类型的ActiveX控件?

Try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM