参考
我试图用VBA更改ActiveX命令按钮的名称属性,具有以下代码:
I am trying to change the name property of ActiveX command buttons with VBA with the following code:
Set shp = ActiveSheet.Shapes(Selection.Name) With shp.OLEFormat.Object .Object.Caption = "Node" & Str(NumNodes) .Name = "Node" & Str(NumNodes) End With我可以更改字幕名称,但是name属性不能用上面的代码改变。我需要找到一个方法来连接名字属性的int(NumNodes)字符串。
I am able to change the caption name, but the name property cannot be changed with the above code. I need to find a way to concatenate a string with an int (NumNodes) for the name property.
更新
这是一个完整的子程序,它会复制一个命令按钮并将其粘贴到特定的单元格位置。属性(如名称和标题)也会在创建按钮时更改。
This is the full subroutine which copies a command button and pastes it to a specific cell location. Properties, such as the name and caption are also changed upon button creation.
Public Sub Node_Button_Duplication() ' 'Comments: Copies and pastes Node 1's button to the appropriate column Dim shp As Shape ' Copy Node 1 button and paste in appropriate location ActiveSheet.Shapes("CommandButton1").Select Selection.Copy Cells(5, 10 + 7 * (NumNodes - 1) - 1).Select ActiveSheet.Paste Selection.ShapeRange.IncrementLeft 47.25 Selection.ShapeRange.IncrementTop -13.5 Set shp = ActiveSheet.Shapes(Selection.Name) With shp.OLEFormat.Object .Object.Caption = "Node" & Str(NumNodes) .Name = "Node" & Str(NumNodes) End With End Sub推荐答案
这是你正在尝试的吗?
Set shp = ActiveSheet.Shapes(Selection.Name) shp.Name = "Node" & Str(NumNodes) With shp.OLEFormat.Object .Object.Caption = "Node" & Str(NumNodes) End WithFOLLOWUP
刚刚尝试过,它的工作原理...
Just tried this and it works...
Public Sub Node_Button_Duication() Dim shp As Shape Dim NumNodes As Long ActiveSheet.Shapes("CommandButton1").Select Selection.Copy Cells(5, 10 + 7 * (NumNodes - 1) - 1).Select ActiveSheet.Paste Selection.ShapeRange.IncrementLeft 47.25 Selection.ShapeRange.IncrementTop -13.5 NumNodes = 5 Set shp = ActiveSheet.Shapes(Selection.Name) shp.Name = "Node" & Str(NumNodes) With shp.OLEFormat.Object .Object.Caption = "Node" & Str(NumNodes) End With End Sub更多关注
MORE FOLLOWUP
尝试这个
Set shp = ActiveSheet.Shapes(Selection.Name) With shp.OLEFormat.Object .Object.Caption = "Node" & Str(NumNodes) .Name = "Node" & NumNodes End With注意,我更改了 Str(NumNodes) 到 NumNodes ?
ActiveX控件名称不能有空格:)
The ActiveX Control Names cannot have spaces :)
现在尝试。
SNAPSHOT
更多推荐
使用Excel中的VBA更改ActiveX命令按钮的名称
发布评论