我想创建一个简单的宏,只需检查复选框是否被选中,并基于此,隐藏或显示行。
但是有一些捕获,我不能将chackbox链接到单元格,否则另一个更大的宏会生成错误。
我研究了一下,发现你可以这样做:
sheets(1).shapes("Checkbox 88").topleftcell.row
以获得形状的行。
所以我试着在我的代码中实现它:
Dim sh As Shape
For Each sh In Sheets(1).Shapes
If TypeOf sh.OLEFormat.Object Is CheckBox Then
If sh.OLEFormat.Object.Value = -4146 Then
'sh.OLEFormat.Object.TopLeftCell.Row.EntireRow.Hidden = True
MsgBox "Hi"
End If
End If
Next sh
我知道:
sh.OLEFormat.Object.TopLeftCell.Row.EntireRow.Hidden = True
是错误的,因为如果我运行宏,因为我张贴它,宏返回msgbox“嗨”,因为错误的部分被注解。
奇怪的是,如果我这样做:
Dim aux As Byte
Dim sh As Shape
aux = Sheets(1).Shapes("Checkbox 88").OLEFormat.Object.TopLeftCell.Row
'checkbox 88 is one of the checkboxes/shapes in the excel document
MsgBox aux
它能让行...
我在想这个错误与OLEFormat.object
或其他什么有关,但我的谷歌研究空手而归。
1条答案
按热度按时间xytpbqjk1#
我会考虑抛弃复选框,用超链接来代替它们,这些超链接的风格就像复选框一样。这样就可以进行排序,复制和粘贴等,而不会有“漂移”的机会,复选框可以从它们分配的行中分离出来。
用于创建和支持链接的代码(在常规模块中)
单击时切换链接外观(工作表代码模块):