View Full Version : Renaming shapes in slide in PowerPoint VBA
CuriosityBug
09-11-2019, 04:35 AM
Hello all,
I am trying to rename shapes in a slide just to make sure name of each shape/object is unique. How can I randomly assign unique ID's/names to each shape?
I got to know that this can be done by changing the name in selection pane. But, I would like a macro to do this task. Is it possible to give random timestamps or any other approach?
John Wilson
09-14-2019, 03:38 AM
Shapes on a slide already have a unique ID. Normally the name is unique too but sadly this is not always the case especially if you copy / paste. What exactly are you trying to achieve?
CuriosityBug
09-16-2019, 09:09 AM
Shapes on a slide already have a unique ID. Normally the name is unique too but sadly this is not always the case especially if you copy / paste. What exactly are you trying to achieve?
Exactly! The slides have shapes that are copied and has same name/duplicate names. I am trying to rename those shapes so that each shape has a unique value.
Something like : ActivePresentation.Slides(3).Shapes.Range(Array(oSh1.name, oSh2.name)).Group
[I can use this approach for grouping mechanism mentioned in my previous thread. Once after renaming them, I will able to access each element in an array and perform group operation]
John Wilson
09-16-2019, 09:17 AM
You could start with this and adapt to suit:
Sub rename()
Dim osld As Slide
Dim oshp As Shape
Dim L As Long
Set osld = ActiveWindow.Selection.SlideRange(1)
For Each oshp In osld.Shapes
If Not oshp.Type = msoPlaceholder Then
L = L + 1
oshp.Name = "myShape" & CStr(L)
End If
Next oshp
End Sub
CuriosityBug
09-16-2019, 11:32 AM
thanks John
You could start with this and adapt to suit:
Sub rename()
Dim osld As Slide
Dim oshp As Shape
Dim L As Long
Set osld = ActiveWindow.Selection.SlideRange(1)
For Each oshp In osld.Shapes
If Not oshp.Type = msoPlaceholder Then
L = L + 1
oshp.Name = "myShape" & CStr(L)
End If
Next oshp
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.