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
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.
msgbox typename(selection); now Ctrl+click and run the same code. If you're only actually interested in charts you could use a simpleset cht = activechartinside an error handler. I confess I had forgotten you can't rename charts that way any more.