gpt4 book ai didi

excel - 在excel中重命名插入的图片

转载 作者:行者123 更新时间:2023-12-04 21:00:51 26 4
gpt4 key购买 nike

插入到excel中的图片会自动命名为“图片1”、“图片2”等。我正在运行一个函数来在所选图片周围放置一个边框。问题是,如果工作表中有两个图像是“图片 1”,该函数会变得困惑,不知道将其放在哪一个上,而是随机将其放在可能不正确的图像上。无论如何要更改图像的名称框或至少获取所选图像?
这是我在图像上放置边框的代码:

Private Function AddImageBorder(WhichSheet As String)

With ActiveWorkbook.Sheets(WhichSheet).Shapes(Selection.Name)
.Line.Weight = 5
.Line.Visible = msoTrue
End With

End Function

最佳答案

尝试这个:

Private Function AddImageBorder()
If TypeName(Selection) = "Picture" Then 'Make sure the object is a picture first
With Selection.ShapeRange
.Line.Weight = 5
.Line.Visible = msoTrue
End With
End If

End Function

我添加了检查以确保选择是图片以防止出现一些错误。

要回答您的直接问题,您可以这样做:
Selection.Name = "NewName" 

它将更改图片对象的名称。

关于excel - 在excel中重命名插入的图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36607282/

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