相关疑难解决方法(0)

请参阅使用代号的表格

我在此代码中遇到"类型不匹配"错误:

With Worksheets(Sheet1)   '* Error here 
   'my code here
End With
Run Code Online (Sandbox Code Playgroud)

我的表CodeName'sheet1'.

有人可以帮我删除错误吗?

excel vba worksheet excel-vba

7
推荐指数
2
解决办法
2万
查看次数

在Excel中使用VBA更改ActiveX命令按钮的名称

参考

我试图用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)

excel vba command

4
推荐指数
1
解决办法
4万
查看次数

标签 统计

excel ×2

vba ×2

command ×1

excel-vba ×1

worksheet ×1