如何重命名新创建的 ActiveX 按钮? [英] How to rename a newly created ActiveX button?

查看:27
本文介绍了如何重命名新创建的 ActiveX 按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Mathieu 的回复,我设法通过

Sub aaaaaaaa()
Dim newButton As Object
Set newButton = Sheets(sheetname_KvE).OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
    Link:=False, _
    DisplayAsIcon:=False, _
    Left:=800, _
    Top:=0, _
    Width:=300, _
    Height:=30).Object
With newButton
    .Caption = "bla"
    '.Name = "Button_what" ' - THIS DOES NOT WORK!
End With
End Sub

如何重命名该按钮?

不幸的是,这些链接没有引导我找到解决方案:

Unfortunately, these links did not lead me to the solution:

https://answers.microsoft.com/en-us/msoffice/forum/all/vba-code-to-modify-the-name-property-of-an-activex/d23b4ee5-aef4-425b-8a19-2899b65651e2

这将是非常棒的,因为它使人们能够在工作表的模块中添加相关代码(据我所知,它们的相关子总是被称为 [insert button name]_Click).

This would be quite glorious, as it enables one to add relevant code in the sheet's module (as far as I can see, they relevant sub is always called [insert button name]_Click).

推荐答案

这是您要尝试的吗?

Sub Sample()
    Dim newButton As OLEObject
    Dim ws As Worksheet
    
    Set ws = Sheets(sheetname_KvE)
    Set newButton = ws.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
                                      Link:=False, _
                                      DisplayAsIcon:=False, _
                                      Left:=800, _
                                      Top:=0, _
                                      Width:=300, _
                                      Height:=30)
    newButton.Object.Caption = "bla"
    newButton.Name = "Button_what"
End Sub

这篇关于如何重命名新创建的 ActiveX 按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆