Solved

Rename Shape or Group in MS Word Document

Posted on 2003-11-03
8
1,067 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

920 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

17 Experts available now in Live!

Get 1:1 Help Now