Excel VBA 自动重命名复选框

发布于 2024-11-09 04:19:48 字数 211 浏览 0 评论 0原文

我目前正在处理几个带有很多复选框的 Excel 工作表。 当您输入复选框时,它的名称为 CheckBox1、CheckBox2 等,但是否可以自动重命名它们? 在我的代码中,我现在必须将所有复选框重命名为 Rij11_1、Rij11_2 等。

如果可以自动逐行完成此操作,将会节省大量时间。

有人知道该怎么做吗?

多谢!

亲切的问候, 马克

I am currently working on a couple of Excel sheets with a lot of checkboxes.
When you enter a checkbox, it has the name CheckBox1, CheckBox2, etc, but is it possible to automatically rename them?
In my code, I now have to rename all checkboxes to Rij11_1, Rij11_2, etc.

It would save me a lot of time if this could be done automatically, row by row.

Does someone know how to do this?

Thanks a lot!

Kind regards,
Marc

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风夜微凉 2024-11-16 04:19:48

假设复选框位于代号为 Sheet1 的工作表上,

Sub test()

Dim obj As OLEObject, ChkBoxRow as long

ChkBoxRow = 1 'Only change checkboxes with topleft corner in row 1

With Sheet1
'Loop AX controls
For Each obj In .OLEObjects
    'Check for checkbox only
    If TypeName(obj.Object) = "CheckBox" Then

        'Examples to identify location (as suggested by Dick Kusleika)
        'ChkBoxRow = obj.TopLeftCell.Row
        'ChkBoxCol = obj.TopLeftCell.Column
        'ChkBoxAdd = obj.TopLeftCell.Address

        'ChkBoxRow = obj.BottomRightCell.Row
        'ChkBoxCol = obj.BottomRightCell.Column
        'ChkBoxAdd = obj.BottomRightCell.Address
        'etc

        if obj.TopLeftCell.Row = ChkBoxRow then
           obj.Name = "Rij11_" & Right(obj.Name, Len(obj.Name) - 8)
        end if

    End If
Next obj
End With
End Sub

我已更新显示一个很好的方法 Dick Kusleika 前几天指出要找到复选框所在的位置。您可以测试 If obj.TopLeftCell.Row = 1 Then

Assuming the Checkboxes are on the sheet with codename Sheet1

Sub test()

Dim obj As OLEObject, ChkBoxRow as long

ChkBoxRow = 1 'Only change checkboxes with topleft corner in row 1

With Sheet1
'Loop AX controls
For Each obj In .OLEObjects
    'Check for checkbox only
    If TypeName(obj.Object) = "CheckBox" Then

        'Examples to identify location (as suggested by Dick Kusleika)
        'ChkBoxRow = obj.TopLeftCell.Row
        'ChkBoxCol = obj.TopLeftCell.Column
        'ChkBoxAdd = obj.TopLeftCell.Address

        'ChkBoxRow = obj.BottomRightCell.Row
        'ChkBoxCol = obj.BottomRightCell.Column
        'ChkBoxAdd = obj.BottomRightCell.Address
        'etc

        if obj.TopLeftCell.Row = ChkBoxRow then
           obj.Name = "Rij11_" & Right(obj.Name, Len(obj.Name) - 8)
        end if

    End If
Next obj
End With
End Sub

I've updated showing a nice method Dick Kusleika pointed out the other day to locate where the checkboxes reside. You can test for If obj.TopLeftCell.Row = 1 Then etc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文