Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Rename Shape or Group in MS Word Document

Posted on 2003-11-03
8
Medium Priority
?
1,159 Views
Last Modified: 2007-12-19
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?
0
Comment
Question by:Blen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 9

Expert Comment

by:gilbar
ID: 9679604
   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
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9684489
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".
0
 

Author Comment

by:Blen
ID: 9689339
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.
0
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
LVL 9

Accepted Solution

by:
gilbar earned 260 total points
ID: 9689755
Blen;
first, to get to the header: ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
next, to get the count of shape in header: sCount = Selection.HeaderFooter.Shapes.Count
so my code now looks linke this:
Sub q()
Dim sCount As Long
Dim Current As Long
Dim bTest As String     'holds the original name
Dim nameStr As String   'holds the new and improved name
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    sCount = Selection.HeaderFooter.Shapes.Count
    Current = 1
    Do While Current <= sCount
        Selection.HeaderFooter.Shapes(Current).Select
        With Selection.ShapeRange
          bTest = .Name                  'bTest now has the Shape's name
          'call something that will take bTest and give you nameStr
          .Name = nameStr             'the shape is now named nameStr
        End With
        Current = Current + 1
    Loop
End Sub

where there's the line " 'call something the will...." you could have a userform that would display bTest in a label and receive nameStr from a textbox.  

0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9689801
>> 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?
0
 

Author Comment

by:Blen
ID: 9689920
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,
0
 
LVL 9

Expert Comment

by:gilbar
ID: 9689952
Glad it worked blen.  
Dreamboat, 32000 more points and it will all be mine!! (assuming you keep letting me hog all the point! ;)
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9689997
Hee hee, gilbar.
Since I don't do code, it shouldn't be too tough!
'sides, you'll see me sporting another title soon.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question