如何在Excel中重命名选定的形状 [英] How to rename the selected shape in Excel
问题描述
如果我选择一个形状,例如图表或文本框,如何在VBA中重命名它?我在PowerPoint中有一个不错的小子和表格,可以做到这一点:
If I select a shape, such as a chart or text box, how can I rename it in VBA? I have a nice little sub and form in PowerPoint that does this:
Sub ShapeName()
If Not ActiveWindow.Selection Is Nothing Then
If ActiveWindow.Selection.Type = ppSelectionShapes Then
NameForm.NameBox.Text = ActiveWindow.Selection.ShapeRange.Name
NameForm.Show
If Not NameForm.bCancel Then
ActiveWindow.Selection.ShapeRange.Name = NameForm.NameBox.Text
End If
End If
End If
End Sub
如何在Excel中实现相同目的?ActiveWindow.Selection对象是非常不同的.我不知道如何从选择导航到所选形状.如果选定的形状是图表对象,那么还将选择源单元格,而我想忽略这些单元格,而只是重命名形状.
How can I achieve the same in Excel? The ActiveWindow.Selection object is very different. I can't work out how to navigat from the selection to the selected shape. If the shape selected is a chart object, then the source cells are also selected, and I want to ignore those and just rename the shape.
推荐答案
这是一个小例子:
Sub ARoseByAnyOtherName()
ActiveSheet.Shapes(1).Select
Selection.Name = "MyRedRose"
End Sub
EDIT#1:
如果我们知道 Selected 对象是图表,请使用:
If we know that the Selected object is a Chart then use:
Sub ARoseByAnyOtherName()
ActiveChart.Parent.Name = "MyRedRose"
End Sub
这篇关于如何在Excel中重命名选定的形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!