我在此代码中遇到"类型不匹配"错误:
With Worksheets(Sheet1) '* Error here
'my code here
End With
Run Code Online (Sandbox Code Playgroud)
我的表CodeName
是'sheet1'
.
有人可以帮我删除错误吗?
我试图用VBA更改ActiveX命令按钮的名称属性,代码如下:
Set shp = ActiveSheet.Shapes(Selection.Name)
With shp.OLEFormat.Object
.Object.Caption = "Node" & Str(NumNodes)
.Name = "Node" & Str(NumNodes)
End With
Run Code Online (Sandbox Code Playgroud)
我可以更改标题名称,但不能使用上面的代码更改name属性.我需要找到一种方法来为name属性连接字符串和int(NumNodes).
UPDATE
这是完整的子例程,它复制命令按钮并将其粘贴到特定的单元格位置.在创建按钮时也会更改属性,例如名称和标题.
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) …
Run Code Online (Sandbox Code Playgroud)