Results 1 to 3 of 3
  1. #1
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    ShapeRange.Name in Word: error in 2010

    Hi all,

    I'm getting an error in code that's worked in all versions of Word up until 2010. I could name a shape then refer to the shape by name in other code. First I would single-click on a shape, then run this code. The naming code is pretty simple:

    Code:
    Sub SetAShapeName()
    Dim strName
    strName = InputBox("Type the name of the shape")
    Selection.ShapeRange.Name = strName
    End Sub
    In 2010 I get an error -- "Method 'Name' of object 'ShapeRange' failed." Of course, "Name" is a read/write property, not a method, so I'm not sure what's going on here.

    Thanks, Kim

  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
    Could the ShapeRange be a collection that requires an index?

  3. #3
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts
    Thanks so much, Jefferson! You provided the key (as you often do...)!

    Selection.ShapeRange is a collection of all shapes within a selection. It doesn't have an Index but it does have an Item Method with which to return a single shape and that's how I fixed this.

    Code:
    Sub SetAShapeName()
    Dim strName
    Dim oShape1 As Shape
    strName = InputBox("Type the name of the shape")
    Set oShape1 = Selection.ShapeRange.Item(1)
    oShape1.Name = strName
    End Sub
    On reflection, this makes sense, since I could have more than one shape in my selection. Could this be a fix in vba 7?

    On the other hand, I still don't have to set an object and return the item to get the shape name. It seems that vba can tell which Item I mean when I select a single shape and run this code:

    strName = Selection.ShapeRange.Name

    Best, Kim (a little less today, thanks to you)

Posting Permissions

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