Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用字符串变量在VBA中设置对象变量?(Excel 2013)_Excel_Excel 2013_Vba - Fatal编程技术网

使用字符串变量在VBA中设置对象变量?(Excel 2013)

使用字符串变量在VBA中设置对象变量?(Excel 2013),excel,excel-2013,vba,Excel,Excel 2013,Vba,我在一个页面上有许多ActiveX控件/按钮,我想修改按钮的几个参数(在循环函数中) 我可以编写循环函数来实现这一点,但无法找到使用字符串变量引用对象的方法。我已经设置了一个对象变量(如下所示)和一个字符串变量,用于更改对象变量的引用,但找不到使其工作的方法 这是不起作用的代码: Set ButtonObj=ButtonString命令失败,报告类型不匹配错误 我在Excel 2013中工作 我真的希望有办法做到这一点。任何帮助都将非常感激 CommandButton属于OLEObject 试一

我在一个页面上有许多ActiveX控件/按钮,我想修改按钮的几个参数(在循环函数中)

我可以编写循环函数来实现这一点,但无法找到使用字符串变量引用对象的方法。我已经设置了一个对象变量(如下所示)和一个字符串变量,用于更改对象变量的引用,但找不到使其工作的方法

这是不起作用的代码:

Set ButtonObj=ButtonString
命令失败,报告类型不匹配错误

我在Excel 2013中工作


我真的希望有办法做到这一点。任何帮助都将非常感激

CommandButton属于
OLEObject

试一试

请注意,一些属性直接出现在
按钮nobj
下,其他属性(如标题)位于对象下方


使用“局部变量”窗口查看属性的层次结构是一个很好的观点。Brett-太棒了。工作完美。谢谢
Private Sub TrialCode_Click()

Dim ButtonObj As Object
Dim ButtonCaption As String
Dim ButtonString As String

ButtonString = "CommandButton1"
Set ButtonObj = ButtonString

ButtonCaption = "Something"

ButtonObj.Caption = ButtonCaption  'example of the kind of parameters I want to change

End Sub
ButtonString = "CommandButton1"
Set ButtonObj = ActiveSheet.OLEObjects(ButtonString)

ButtonCaption = "Something"
ButtonObj.Object.Caption = ButtonCaption  'example of the kind of parameters I want to change