Consulting

Results 1 to 11 of 11

Thread: How to access shapes with same name?

  1. #1

    Question How to access shapes with same name?

    Hi,
    I am Prabhakaran - a VBA Developer doing automation for more than five years in excel and Access, but very new to the powerpoint Object model. Currently doing an Automation in Powerpoint where in one slide there are two shapes having the exact samename (Content Placeholder 8). How to access them individually through code? And I have one more doubt: What is the difference between a table and a Content Placeholder? Acutally here in this presentation template I am seeing only tables named as Content Placeholder 8. Why its looking like a table but having a different name? Work at stake. Kindly help.
    Regards,
    Prabhakaran

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    No. It is impossible to have two Shapes on one Slide with the same Name.

    Select each "Shape" on the slide and discover it's Type. Type 1 = Slide; Type 2 = Shape; Type 3 = Text
    Then discover the "Shape's" Parent Name and Type.

    Sub WatchX()
     Dim X
     
       With Selection 
          X = .Type
          X =  .Name
          With .Parent
             X = .Type
             x = .Name
         End With
         With Parent.Parent
            'Continue
         End With
       End With
    End Sub
    A Table is an Object and "Content Placeholder (n)" is a name that is automatically assigned when certain objects are added. The same as new Worksheets in Excel are named "Sheet(n)". You are probably seeing Tables named "Content Placeholder (n)"
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    It's not impossible to have shapes with the same name in PPT. (Not clever of MSFT but easy to achieve.)
    Two placeholders with the same name it not easy to achieve though. How did you do this. However it's going to cause you pain.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Please clarify for me; Is it possible to have two Shapes with the same Name in the same Slide? If so, How?

    I have very little experience with PPT and all that with 2002 and 97.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    It is Sam (not clever though) You can rename the shapes in the selection pane to have the same name (people don't usually do this) OR rename one shape say to myShape and then copy and paste. The new shape will also be called myShape I think this only works after 2007 but not sure. It should be impossible but it isn't!

    If you access and modify the shape with code only the first shape in the zorder will be affected.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    thanks.

    Can you help the OP? I've just been muddling along.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Very hard coded way to tell two ContentPlaceHolders with the same name apart (the left one and the right one)

    No error checking AT ALL

    John's taught me a lot about the PP object model, but I still wish PP had an Excel quality macro recorder

    Also, while the .Name properties can be the same, the .Id properties are still different

    Option Explicit
    Sub test()
        Dim oPresentation As Presentation
        Dim oSlide As Slide
        Dim oShape As Shape
        Dim oContentLeft As Shape, oContentRight As Shape
        
        Set oPresentation = ActivePresentation
        Set oSlide = oPresentation.Slides(2)
        
        For Each oShape In oSlide.Shapes
            With oShape
                If .Name = "Content Placeholder 8" Then
                    If oContentLeft Is Nothing And oContentRight Is Nothing Then
                        Set oContentLeft = oShape
                    Else
                        Set oContentRight = oShape
                    End If
                End If
            End With
        Next
      
        If oContentLeft.Left > oContentRight.Left Then
            Set oShape = oContentLeft
            Set oContentLeft = oContentRight
            Set oContentRight = oShape
        End If
      
      
        MsgBox "Left one = " & oContentLeft.Id
        MsgBox "Right one = " & oContentRight.Id
      
      
    End Sub
    Once you have the 2 shapes Set, then you can test or do things

    Look at the attached file if you want, but save it and just rename it to remove the .zip part since I can't seem to upload .PPTM files
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    The other approach is to open the slide masters on the template and rename them so you don't need to worry about the same names

    All presentation created using your revised template will have your names
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  9. #9
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Paul's right you need to rename but also work out HOW they have the same name.Usually this involves copy and pasting placeholders which is always a bad idea! Any quick fix is going to give future pain!

    In any case placeholders on slides do not inherit the name from the master and it is pretty difficult to link a slide placeholder to it's parent. The time to rename on a slide is as the slide is created when the placeholders will share position with the masters.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  10. #10
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Acutally here in this presentation template I am seeing only tables named as Content Placeholder 8. Why its looking like a table but having a different name? Work at stake. Kindly help.
    Regards,
    Prabhakaran
    Another question ... the 'template' ...

    a. Is it literally a .POTX or .POTM and in the Microsoft\Templates folder, (similar to .XLST or .XLTM) OR

    b. Is it 'company standard' .PPTX or .PPTM that is copied and saved with a new name? (similar to .XLSX or .XLSM)

    If it's a). then FileNew will create s new presentation (either .PPTX or .PPTM) so you'd want to fix the names there

    If it's b). then I'd investigate creating a true template (a.)



    but also work out HOW they have the same name.Usually this involves copy and pasting placeholders which is always a bad idea!
    For sure, but Control-C/Control-V will copy a Content Place Holder if it's not empty. BUT Control-Click-Drag will create a copy of the empty one. In both cases the names are the same

    Using the Selection Pane, it's easy to give them meaningful names ('List of Pros' and 'List of Cons', etc.). Same for other shapes, so instead of 'Picture 8' you could call the shape 'Company Logo'
    Last edited by Paul_Hossler; 12-21-2014 at 09:50 AM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  11. #11
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Ctrl C/V copies a placeholder on the master / layout and the name will be the same but on the slide in normal view they will get (should get) new different names. If you copy paste on the normal slide the name will duplicate but the pasted shape is not really a placeholder and will not really follow the master. Whatever it's a bad idea. Oh and if it's not a potx/m then as Paul says it should be.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Tags for this Thread

Posting Permissions

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