?
Solved

Autonumbering of figures in Word

Posted on 2003-02-26
6
Medium Priority
?
595 Views
Last Modified: 2008-02-01
Hi,

I would like to be able to autonumber figures (grouped autoshapes etc), just like LaTex does for example.

So, I added a caption (from the insert menu) to my figure and grouped the caption with it.

Unfortunately, (due to a Bug?) Word does not update the fields inside a grouped object. It seems such a basic thing, numbering figures, but Word does not seem to support this.

I wrote a macro to ungroup all shapes (it does not work if I ungroup one shape at a time), remember the original groups, update all fields, and regroup.

The macro almost works, but the problem is that once ungrouped, the parts often scatter all over the document. If I regroup, parts don't always regroup in the same combination, and rarely does the regrouped shape appears at the original location again.

This is my macro so far. I only learned VBA a day ago, so the code may not be that fancy. I hope someone can suggest an improvement, or perhaps knows of another way of numbering figures.

Sub updateFigures()

Dim shapeArray(1 To 50) As ShapeRange
Dim totalGroups As Integer
Dim bla As Collection
Dim sShape As Shapes
Dim qwe As ShapeRange
Dim myshape As ShapeRange
Dim nCounter As Integer

Dim origShapeArray(1 To 50) As Shape 'how to set a dynamic size ?
Dim origAnchorArray(1 To 50) As Range 'for now, 50 will do
Dim dupShape As Shape

totalGroups = 0

Set sShape = ActiveDocument.Shapes
    For nCounter = sShape.Count To 1 Step -1
       
        ' ungroup all grouped shapes
        If (sShape(nCounter).Type = Office.MsoShapeType.msoGroup) Then
                   
           totalGroups = totalGroups + 1
           
           'selecting Anchor prevents scattering of parts a bit
           sShape(nCounter).Anchor.Paragraphs(1).Range.Select
           Set origAnchorArray(totalGroups) = sShape(nCounter).Anchor
           
       
           'remember original shape, doesn't help much...
           Set dupShape = sShape(nCounter).Duplicate
           dupShape.Visible = msoFalse
           Set origShapeArray(totalGroups) = dupShape
           
           Set qwe = sShape(nCounter).Ungroup
                     
           Set shapeArray(totalGroups) = qwe
        End If
   
    Next nCounter
   
    ' update all fields if shapes have text
    For nCounter = 1 To totalGroups Step 1
       
        Set myshape = shapeArray(nCounter)
        Dim groupCnt As Integer
   
        For groupCnt = myshape.Count To 1 Step -1
            If myshape(groupCnt).TextFrame.HasText Then
               myshape(groupCnt).Select
               Selection.WholeStory
               Selection.Fields.Update
            End If
        Next groupCnt
       
    Next nCounter
       
    Dim regroupedShape As Shape
    Dim origShape As Shape
    Dim origAnchor As Range
       
    ' regroup shapes back
    For nCounter = 1 To totalGroups Step 1
       
        Set myshape = shapeArray(nCounter)
        ' select the same Anchor as the original shape was linked to
        Set origAnchor = origAnchorArray(nCounter)
        origAnchor.Paragraphs(1).Range.Select
        Set regroupedShape = myshape.Regroup
        regroupedShape.Select
       
        Set origShape = origShapeArray(nCounter)
               
        'Copy most of the original properties back
        Selection.ShapeRange.Fill.Transparency = origShape.Fill.Transparency
        Selection.ShapeRange.Line.Style = origShape.Line.Style
        Selection.ShapeRange.Line.Transparency = origShape.Line.Transparency
        Selection.ShapeRange.Line.BackColor.RGB = origShape.Line.BackColor.RGB
        Selection.ShapeRange.LockAspectRatio = origShape.LockAspectRatio
        Selection.ShapeRange.Height = origShape.Height
        Selection.ShapeRange.Width = origShape.Width
        Selection.ShapeRange.RelativeHorizontalPosition = origShape.RelativeHorizontalPosition
        Selection.ShapeRange.RelativeVerticalPosition = origShape.RelativeVerticalPosition
        Selection.ShapeRange.Left = origShape.Left
        Selection.ShapeRange.Top = origShape.Top
        Selection.ShapeRange.LockAnchor = origShape.LockAnchor
        Selection.ShapeRange.WrapFormat.AllowOverlap = origShape.WrapFormat.AllowOverlap
        Selection.ShapeRange.WrapFormat.Side = origShape.WrapFormat.Side
        Selection.ShapeRange.WrapFormat.DistanceTop = origShape.WrapFormat.DistanceTop
        Selection.ShapeRange.WrapFormat.DistanceBottom = origShape.WrapFormat.DistanceBottom
        Selection.ShapeRange.WrapFormat.DistanceLeft = origShape.WrapFormat.DistanceLeft
        Selection.ShapeRange.WrapFormat.DistanceRight = origShape.WrapFormat.DistanceRight
        Selection.ShapeRange.WrapFormat.Type = origShape.WrapFormat.Type
       
        origShape.Delete
       
    Next nCounter
   
   
End Sub
0
Comment
Question by:henk53
[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
6 Comments
 
LVL 2

Expert Comment

by:ykchick
ID: 8028918
Word does have autonumbering for figures. They call it captioning and you can customize it to apply to different types of objects - excel charts, word pictures, etc. Unfortunately, it seems that autoshapes are one of the few types of figures that aren't on the list.

I found you could add captions to an autoshape (grouped or otherwise) if you create the autoshape in another word document (you don't need to save it), then Copy/Paste Special it as a picture instead of autoshape. However, it was still a bit glitchy (created a visible text box around the caption instead of doing a tidy caption like it did for other types of figures).

How many of your figures are autoshapes and how many are other formats? If there are only a few that are autoshapes, it might be worth playing with the captioning because it works well for the figure types on the preset list. However, if they are almost all autoshapes, it may be more trouble than it's worth.

If you want more details on the autonumbering through captions, let me know. Also, I only played with this for a few minutes so it may be possible to get it working more smoothly with autoshapes as well.

0
 

Author Comment

by:henk53
ID: 8032589
Hmmmm, well it's an interesting aproach. I tried what you said, but the kind of caption Word adds to a picture is exactly the same kind of caption you can (manually) add to an autoshape. Just try selecting an autoshape (grouped or not) and select 'caption' from the insert menu.

The visible text box is easy enough to get rid of, just right click the box and select 'Format text box...' from the context menu.

The problem though, is exactly the same with these pictures. As soon as you group the caption text box with the picture, Word does not update the field (SEQ) anymore.
Neither does manual updating work.

The obviously solution would be to simply not group a caption with an autoshape. However, when I do that, and add text to my document, Word often places the autoshape (of picture) on the bottom of one page and the caption box on the top of the next.

I think the problem is more fundamental than we might think. Word has so much legacy code in it. Autoshapes were added relatively late to the series, and their 'field processing code' is obviously not at all compatible with them.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 9283605
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in the next round.  I would appreciate any comments by the experts that would help me in making a recommendation.


It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp

PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER

HAGD:O)Bruintje
EE Cleanup Volunteer
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:henk53
ID: 9299132
I am still interested in the answer, but to be honest I think the problem is unsolvable; that is Word 2000 and earlier are simply lacking this feature or have a bug in their implementation.

On the bright side, I do have been able to autonumber figures where the caption is grouped with the figure, but it only works in Word XP. The trick is to set tools->options->print->update fields. Then, do a print (to file, so not to waste paper) and the numbers will be updated. CTRL-A + F9 does not work.
Again, this only works in Word XP.

It works most conviently by putting the figure (after the caption has been grouped with it) in a drawing canvas, and use a "style" to control the distance between the figure and the surrounding text (top and bottom). Use draw->relative to canvas to center the figure.

Unfortunately there are still some glitches. Although field updating now works, the build-in TOF as found in Insert->Reference->Index and Tables->Table of Figures does not see {seq figure} fields in the caption, and therefore does not work. The Insert->Reference->Cross Reference->Numbered item/Figure + Page number does not work either. The cross-reference always outputs 0, no amount of field updating puts it to the real page number.

0
 
LVL 3

Expert Comment

by:crimper
ID: 9560974
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ/No Refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

John Pullin
EE Cleanup Volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 9603781
PAQed - no points refunded (of 75)

Computer101
E-E Admin
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
New style of hardware planning for Microsoft Exchange server.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

777 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