Solved

Rename Shape or Group in MS Word Document

Posted on 2003-11-03
8
1,050 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
  • 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
 
LVL 9

Accepted Solution

by:
gilbar earned 65 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now