Results 1 to 14 of 14
  1. #1
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    How to Rename Slide Objects (PPT 2K/XP)

    Anybody know how to rename objects (shapes, placeholders, etc) on a slide? Or, if that is asking too much, at least be able to view the object name in the PPT UI w/o having to loop thru the slide's objects in VBA to figure out which object "Rectangle 1", etc refers to. According to Help file the Name property for Shape objects is read/write:
    <hr>Shape or ShapeRange objects. When a shape is created, Microsoft PowerPoint automatically assigns it a name in the form ShapeType Number, where ShapeType identifies the type of shape or AutoShape, and Number is an integer that's unique within the collection of shapes on the slide. For example, the automatically generated names of the shapes on a slide could be Placeholder 1, Oval 2, and Rectangle 3. To avoid conflict with automatically assigned names, don't use the form ShapeType Number for user-defined names, where ShapeType is a value that is used for automatically generated names, and Number is any positive integer. A shape range must contain exactly one shape. Read/write String.<hr>
    When I tried renaming object in VBA, using syntax like this:

    Application.Presentations(1).Slides(1).Shapes(1).N ame = "TITLE"

    It seemed to work:

    ? Application.Presentations(1).Slides(1).Shapes(1).N ame
    TITLE

    But when saved file & reopened:

    ? Application.Presentations(1).Slides(1).Shapes(1).N ame
    Rectangle 2

    In other words, did not "stick". Reason for question: For a current project I'm creating/modifying slides dynamically in VBA, using "template" slides w/ predefined styles, formatting, etc, & it'd be useful to be able to refer to slide objects by some name more meaningful than "Rectangle 2", etc.

    Any suggestions would be appreciated - I'm a real PowerPoint dummy [insert smilie with Dunce cap here] & am probably missing something obvious....

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: How to Rename Slide Objects (PPT 2K/XP)

    While I can't answer your question, you might find the Tags collection more stable, as neither PPT nor VBA is likely to use it for anything. Try this on a disposable copy of a presentation:
    <pre>Sub ShapeTaggerReader()
    Dim shp As Shape, intShapeNum As Integer, intCounter As Integer
    For Each shp In ActivePresentation.Slides(1).Shapes
    intShapeNum = intShapeNum + 1
    If shp.Tags.Count = 0 Then
    shp.Tags.Add Name:="MyTagName", Value:="Shape No. " & intShapeNum
    Else
    For intCounter = 1 To shp.Tags.Count
    MsgBox shp.Name & ":" & vbCrLf & _
    shp.Tags.Name(intCounter) & " = " & shp.Tags.Value(intCounter)
    Next
    End If
    Next
    End Sub</pre>

    Potentially useful?

  3. #3
    3 Star Lounger
    Join Date
    Dec 2002
    Location
    USA
    Posts
    397
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to Rename Slide Objects (PPT 2K/XP)

    Oh, man, I *so* don't speak code; I just rely on others to provide me with goodies and addins. <g>

    Steve Rindsberg has a nice set of PPTools. The "starter set" has an editing toolbar, and the "piggy" tool can be used to rename items, if I recall correctly.

    Probably worth a look, anyway. (Especially since that starter set is free!)

  4. #4
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: How to Rename Slide Objects (PPT 2K/XP)

    Thanx for suggestion - the Tag property looks useful. So there is no way to rename the shape itself?

  5. #5
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: How to Rename Slide Objects (PPT 2K/XP)

    Mark,

    FWIW, I had a similar issue with creating shapes in Excel. The answer I got from the Lounge was that you had to name the shape right after it was created if you wanted to be able to refer to a particular shape by a known name. No one suggested the Tag approach that Jefferson suggested. I suspect that there are probably a lot of similarities between Excel and PPT as far as shapes go.

    I experimented with Jefferson's code. Started by creating 1 slide. PPT wanted to create a Title Slide but I changed the layout to a blank slide. Then I added shapes. The first one was named "Rectangle 4", the next "Rectangle 5", then "Oval 6", etc. Of course, these were numbered "Shape No. 1", etc. with Jefferson's code.

    That got me to wondering what happened to shapes 1, 2, and 3. So I created another new presentation with 1 slide. This time I kept the 2 placeholders for the Title Slide. Using Jefferson's code, I surmised these were "Rectangle 2" and "Rectangle 3". So even tho I had changed the layout in the first experiment, it seems the numbers 2 and 3 were reserved for them anyway.

    But what is shape 1 and what kind of a shape is it?

    Fred

  6. #6
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How to Rename Slide Objects (PPT 2K/XP)

    You can and should rename your shapes. PoPo just dosn't give you an easy way to do it. I usually use something like the following:
    <pre>Option Explicit

    Sub List()
    If ActiveWindow.Selection.Type = ppSelectionShapes Then _
    MsgBox ActiveWindow.Selection.ShapeRange.Name
    End Sub

    Sub Name()
    Dim rsp As Variant
    If ActiveWindow.Selection.Type = ppSelectionShapes Then
    rsp = InputBox("Gimme name")
    If rsp <> "" Then
    ActiveWindow.Selection.ShapeRange.Name = rsp
    End If
    End If
    End Sub</pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  7. #7
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How to Rename Slide Objects (PPT 2K/XP)

    I cannot reproduce your "did not stick." I ran the following:
    <pre>Sub test()
    Application.Presentations(1).Slides(1).Shapes(1).N ame = "TITLE"
    End Sub</pre>


    I then saved the changes, closed the presentation, reopened the presentation, selected the top placeholder, ran my List macro, and it produced "TITLE." Are you sure that you saved the presentation after changing the shape names?
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  8. #8
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: How to Rename Slide Objects (PPT 2K/XP)

    Well I'm pretty sure I saved, closed, & re-opened file.... I tried again w/copy of same file. I ran this sub to rename any shape with a text range (in this case I'm not concerned with lines, etc w/no text):

    Public Sub RenameShapes()

    Dim shp As Shape

    For Each shp In ActivePresentation.Slides(1).Shapes
    If shp.HasTextFrame = msoTrue Then
    If Len(shp.TextFrame.TextRange.Text) > 0 Then
    shp.Name = Left(shp.TextFrame.TextRange.Text, 12)
    Debug.Print shp.Name
    End If
    End If
    Next shp

    Set shp = Nothing

    End Sub

    Then ran:

    For Each shp In ActivePresentation.Slides(1).Shapes
    Debug.Print shp.Name
    Next shp

    The shapes with text appeared to be renamed. But when saved, closed, & reopened file, and ran above code, what I got was:

    Text Box 248
    Line 250
    Rectangle 251
    Line 252
    Text Box 253

    etc.... in other words, the shape names reverted to their original generic names. As fburg suggested in his reply, maybe you can only name shape when it is first created? But the property is allegedly read-write. So then tried modifying RenameShapes sub to include extra line (bold):

    Next shp
    ActivePresentation.Save
    Set shp = Nothing

    When ran revised sub with "Save" instruction, closed & re-opened file, and the new names "stuck" this time. Saving file in user interface apparently does not work (I saved "manually" both in VBE & application windows).

    Thanx to all for replies, another PowerPoint mystery solved....

  9. #9
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How to Rename Slide Objects (PPT 2K/XP)

    Glad that you got it to work, but still confused as to when it does not work. Were you on PP2k or PPxp? How do you save when it dosn't work? Thanks! --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  10. #10
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: How to Rename Slide Objects (PPT 2K/XP)

    The project in question is being run on both XP & 2K, but it was in PPT XP that problem occurred. It did not work (renamed object names did not "stick") when changed name in VBA, then saved PPT file using standard toolbar "Save" button in application (UI) window, and/or "Save" button in VBE window. I tested this repeatedly w/ same results. Saving presentation in code did work. This doesn't make much sense, but does not surprise me....

  11. #11
    New Lounger
    Join Date
    Apr 2003
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to Rename Slide Objects (PPT 2K/XP)

    The few times I've seen this behaviour have been when...
    a) User forgets to save the presentation after the name has been manipulated
    [img]/forums/images/smilies/cool.gif[/img] The presentation starts acting weird when VBA is used when referencing shapes by their names. The solution for this has been a workaround- save the presentation as HTML and then re-import it back into PPT. Then trying saving the names it should work.

    Are you experiencing the behaviour with a new presentation too?

    Since you are renaming shapes, please note that, renaming shapes can lead to a undocumented PPT VBA bug if you copy/paste the shapes which have been renamed. You will have shapes with duplicate names on the same slide.

    Regards
    Shyam Pillai

  12. #12
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: How to Rename Slide Objects (PPT 2K/XP)

    Shyam,

    just curious about the bug you mention. As I had indicated earlier in the thread, I had a similar issue in Excel VBA with shapes and assumed it would be the same for ppt.

    Windows has a behavior that if you copy a file and paste it (or "copy here"), it will pre-pend "Copy of" and then the original file name. Windows is sticky about having different file names in the same folder and forces its way.

    In VBA, I would assume that copying a shape and pasting it would result in the same name. I would further assume VBA does NOT pre-pend "Copy of" the name of the shape. But even if I copied a "new" shape such as "Rectangle 2", the pasted version would also be "Rectangle 2". If I had renamed the original "Rectangle 2" to be "green rectangle" and then copied and pasted the shape, the extra copy would be named "green rectangle".

    Are you saying the bug has something to do with renaming and then copying/pasting? If I copied/pasted "Rectangle 2", the bug would not manifest itself and I would get some kind of a warning that I don't get if I rename first?

    Maybe this is for the VBA board but we've gone down the path pretty far here.

    thanks.

    Fred

  13. #13
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: How to Rename Slide Objects (PPT 2K/XP)

    Fred,

    Simple experiment shows the following behaviour...
    <UL><LI>Create an autoshape - it gets the name "Rectangle 3"
    <LI>Copy it and paste a few times - they get the names "Rectangle 4", "Rectangle 5" etc.
    <LI>Execute the command
    ActivePresentation.Slides(1).Shapes(4).Name = "Stuart"
    <LI>Copy and paste the shape called Stuart, and I now have two shapes with the same name[/list]StuartR

  14. #14
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: How to Rename Slide Objects (PPT 2K/XP)

    Hi Stuart,

    Thks for the experimental results. That is poor - not your work but MS's naming strategy.

    Fred

Posting Permissions

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