参考p>
我正在尝试使用以下代码使用 VBA 更改 ActiveX 命令按钮的名称属性:
设置 shp = ActiveSheet.Shapes(Selection.Name)使用 shp.OLEFormat.Object.Object.Caption = "节点" &Str(NumNodes).Name = "节点" &Str(NumNodes)结束于我可以更改标题名称,但无法使用上述代码更改名称属性.我需要找到一种方法将字符串与 name 属性的 int (NumNodes) 连接起来.
更新
这是完整的子程序,它复制命令按钮并将其粘贴到特定的单元格位置.创建按钮时也会更改名称和标题等属性.
公共子节点_Button_Duplication()''注释:将节点 1 的按钮复制并粘贴到相应的列将 shp 变暗为形状' 复制节点 1 按钮并粘贴到适当的位置ActiveSheet.Shapes("CommandButton1").Select选择.复制单元格(5, 10 + 7 * (NumNodes - 1) - 1).SelectActiveSheet.Paste选择.ShapeRange.IncrementLeft 47.25Selection.ShapeRange.IncrementTop -13.5设置 shp = ActiveSheet.Shapes(Selection.Name)使用 shp.OLEFormat.Object.Object.Caption = "节点" &Str(NumNodes).Name = "节点" &Str(NumNodes)结束于结束子 解决方案这是你正在尝试的吗?
设置 shp = ActiveSheet.Shapes(Selection.Name)shp.Name = "节点" &Str(NumNodes)使用 shp.OLEFormat.Object.Object.Caption = "节点" &Str(NumNodes)结束于跟进
刚刚试了一下,效果很好……
公共子节点_Button_Duication()将 shp 变暗为形状调暗 NumNodesActiveSheet.Shapes("CommandButton1").Select选择.复制单元格(5, 10 + 7 * (NumNodes - 1) - 1).SelectActiveSheet.Paste选择.ShapeRange.IncrementLeft 47.25Selection.ShapeRange.IncrementTop -13.5节点数 = 5设置 shp = ActiveSheet.Shapes(Selection.Name)shp.Name = "节点" &Str(NumNodes)使用 shp.OLEFormat.Object.Object.Caption = "节点" &Str(NumNodes)结束于结束子更多跟进
试试这个
设置 shp = ActiveSheet.Shapes(Selection.Name)使用 shp.OLEFormat.Object.Object.Caption = "节点" &Str(NumNodes).Name = "节点" &节点数结束于注意,我把 Str(NumNodes) 改成了 NumNodes?
ActiveX 控件名称不能有空格:)
立即尝试.
快照
Reference
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 WithI 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.
UPDATE
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解决方案
Is this what you are trying?
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 SubMORE FOLLOWUP
Try this
Set shp = ActiveSheet.Shapes(Selection.Name) With shp.OLEFormat.Object .Object.Caption = "Node" & Str(NumNodes) .Name = "Node" & NumNodes End WithNotice, I changed Str(NumNodes) to NumNodes?
The ActiveX Control Names cannot have spaces :)
Try now.
SNAPSHOT
更多推荐
在 Excel 中使用 VBA 更改 ActiveX 命令按钮的名称
发布评论