Solved

Rename Shape or Group in MS Word Document

Posted on 2003-11-03
8
1,078 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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
 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

776 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