Link to home
Start Free TrialLog in
Avatar of Blen
BlenFlag for New Zealand

asked on

Rename Shape or Group in MS Word Document

I have created a document, used for labelling, with a number of different groups of shapes and JPEG's in the header and footer layer of the document. Different groups are selected and brought to the front by part of the VBA code that controls input of variables, formatting, and printing of the document. Each time I modify the document by adding a new group, for a specific new label, the group gets allocated a name like "Group 12" or "Group 84" or whatever.
My question is how do I discover the name of the group without recording a macro whilst performing some action upon the group, and once I have discovered the group name, how can I rename it with a designation more suitable for my purposes like "Label 1" for instance?
Avatar of gilbar
gilbar

   sCount = ActiveDocument.Shapes.Count
    Current = 1
    Do While Current <= sCount
        ActiveDocument.Shapes(Current).Select
        With Selection.ShapeRange
          bTest = .Name                  'bTest now has the Shape's name
          .Name = nameStr             'the shape is now named nameStr
        End With
        Current = Current + 1
    Loop

Here's a clip from some code we use (DON'T just paste this in and run it, it's just an example)
It loops through all the shapes and on each one places the shape's name into bTest.  Then it changes the name of that shape to nameStr.  To use it, you'd need to have nameStr change each time and probably look at bTest.  The code I cut this out of changes Autoshapes to textboxes through a bunch of stuff that i didn't include.
The Important Line is:
              Selection.ShapeRange.Name
Let me know if you have questions
Avatar of Anne Troy
Blen: Are the groups ALWAYS different? Or are they sometimes the same and you're just getting new IDs for them? Have you thought about using autotext for this? I could be way off, tho. If you used autotext, you can give your own name for each "group".
Avatar of Blen

ASKER

Thanks for your responses, and apologies for the delay in replying. To clarify the issue, the groups in question are groups of graphics placed in the header / footer layer of the document. These groups are backgrounds for labels that have essentially the same format, but require different graphics such as customer logo's printed on them. I achieved this by creating the graphics and placing them in the header / footer layer with a large white shape in front of all of them, then bringing the required graphic to the front, making it the only one visible. I was forced to used the the header / footer layer for the graphics due to the peculiarities of the BarDIMM module that I use for decoding and printing the barcode that is also required on the labels. This device does not, for some reason, print barcodes correctly if there is a graphic in the text layer of the document.
Each time I am required to add a different customers graphic to the label, I create a new section of VBA code that selects the graphic (or group of graphics) and brings it to the front. My problem is with discovering what the name of the graphic or group is, and how to change it to a more logical name, that would probably reflect its relationship to the particular customer that it applies to.
Regards.
ASKER CERTIFIED SOLUTION
Avatar of gilbar
gilbar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> I create a new section of VBA code that selects the graphic (or group of graphics) and brings it to the front.

Seems to me you could in fact use autotext for this instead of the workaround you're using.
Have you tried it?
Avatar of Blen

ASKER

Thanks for your help. Worked perfectly, Gilbar, with:

 nameStr = InputBox("New name to replace " & bTest, , bTest)

inserted where you recommended.

Thanks also for your time Dreamboat, I'll try your ideas when I get some time!

Regards,
Glad it worked blen.  
Dreamboat, 32000 more points and it will all be mine!! (assuming you keep letting me hog all the point! ;)
Hee hee, gilbar.
Since I don't do code, it shouldn't be too tough!
'sides, you'll see me sporting another title soon.