gpt4 book ai didi

excel - 用单元格确定形状位置

转载 作者:行者123 更新时间:2023-12-04 20:05:07 26 4
gpt4 key购买 nike

我有一个 Excel 日历,其中某些单元格上有一个形状。我希望能够查看哪些单元格具有形状,然后能够提取一些数据。
我搜索了一下,发现最好的选择是使用 TopLeftCell.Row 但我的代码似乎有错误。我复制了一个代码并尝试对其进行调整,这里是:

Sub ActiveShapeMacro()

Dim ActiveShape As Shape
Dim UserSelection As Variant

'Pull-in what is selected on screen
Set UserSelection = ActiveWindow.Selection

'Determine if selection is a shape
On Error GoTo NoShapeSelected
Set ActiveShape = ActiveSheet.Shapes(UserSelection.Name)
On Error Resume Next

'Do Something with your Shape variable
Cells(Sheet1.Shapes(ActiveShape).TopLeftCell.Row, Sheet1.Shapes(ActiveShape).TopLeftCell.Column).Address
MsgBox (ActiveShape.Address)

Exit Sub

'Error Handler
NoShapeSelected:
MsgBox "You do not have a shape selected!"


End Sub

谢谢您的帮助! :)

最佳答案

错误在于:

Sheet1.Shapes(ActiveShape)

在哪里 Shapes在您提供 Object 时正在等待字符串(形状名称) (形状本身)

所以使用:
'Do Something with your Shape variable
MsgBox Cells(ActiveShape.TopLeftCell.Row, ActiveShape.TopLeftCell.Column).Address

可以简化为:
   MsgBox ActiveShape.TopLeftCell.Address

此外变化:
On Error Resume Next 

至:
On Error GoTo 0

并继续观察那里发生的事情......

关于excel - 用单元格确定形状位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49325115/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com