Consulting

Results 1 to 5 of 5

Thread: Renaming shapes in slide in PowerPoint VBA

  1. #1

    Renaming shapes in slide in PowerPoint VBA

    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?

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Quote Originally Posted by John Wilson View Post
    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]

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    thanks John
    Quote Originally Posted by John Wilson View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •