我有多個形狀,當單擊它時,它會在我的 Excel 作業表中執行操作(我的代碼如下)。但除了這些之外,我還想更改位于我單擊的形狀右側 2 個單元格的形狀的大小。如果不參考我要調整大小的形狀的名稱,我該如何做到這一點?
這是我的代碼。
Sub ArrowClick()
With ActiveSheet.Shapes(Application.Caller).TopLeftCell
.EntireRow.Borders(xlEdgeBottom).LineStyle = xlNone
With .EntireRow.Offset(1, 0).Resize(9)
.EntireRow.Hidden = Not .Hidden
End With
End With
End Sub
uj5u.com熱心網友回復:
請使用下一種方式。它將選擇單擊形狀行的第二列上的形狀并將其寬度加倍:
Sub ArrowClick()
Dim nextSh As Shape
With ActiveSheet.Shapes(Application.Caller).TopLeftCell
.EntireRow.Borders(xlEdgeBottom).LineStyle = xlNone
With .EntireRow.Offset(1, 0).Resize(9)
.EntireRow.Hidden = Not .Hidden
End With
Set nextSh = findNextSh(.Offset(0, 2).Address)
If Not nextSh Is Nothing Then
nextSh.width = nextSh.width * 2
nextSh.Select
End If
End With
End Sub
Function findNextSh(strRange As String) As Shape
Dim sh As Shape
For Each sh In ActiveSheet.Shapes
If sh.TopLeftCell.Address = strRange Then
Set findNextSh = sh: Exit Function
End If
Next sh
End Function
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/406844.html
標籤:
上一篇:在QML中添加QTreeView
