Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Include Section number in captions

Posted on 2004-10-26
8
Medium Priority
?
374 Views
Last Modified: 2013-11-18
I have 5 sections in my document, all created by inserting section breaks

I would like each table in each section to have the section number as part of its caption numbering

Eg,
A table in section 1 will be Table 1.1, Table 1.2.....Table 1.xx
A table in section 3 will be Table 3.1, Table 3.2......Table 3.xx

I follow the steps
Insert > Reference > Caption > Numbering
Then, check Include Chapter Number...which WONT work, as i dont use Heading 1 to Heading X in my document. I do have a numbered style called Main Header at the top of each section, which is numbered exactly as the section numbers

How do i use the numbering from the Main Header style, or include the section numbers in the captions ?

EDIT: Should have mentioned this, sorry..Im using Word 2003 SP1 (11.6359.6360)
Hope thats not impossible, or at least a way to get the numbering right
0
Comment
Question by:etdwh
[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
8 Comments
 
LVL 5

Expert Comment

by:AntonioP
ID: 12411334
You could insert it into your caption afterwards.  Create the caption without the reference, then click in the caption at the correct location and insert a cross-reference to the numbered list.  It seems to survive updating.  You might wait to see if anyone has a better solution.
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12412769
The following will add the table number, as text, after the table.  I could not get it to add a caption (the .InsertCaption function did not work for me), but it should give you some idea as to how to get the table number, at least:

    Sub InsertTableNumber()
   
        Dim oSec As Word.Section
        Dim oTab As Word.Table
        Dim oPar As Word.Paragraph
       
        For Each oSec In ActiveDocument.Sections
       
            iTab = 0
           
            For Each oTab In oSec.Range.Tables
           
                iTab = iTab + 1
                sTab = CStr("Table " & oSec.Index & "." & iTab)
               
                oTab.Range.Next.InsertBefore sTab & vbCrLf & vbCrLf
               
            Next oTab
           
        Next oSec
   
    End Sub

HTH

J.
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12412971
Add the following line:

                      oTab.Range.Next.Style = "Caption"

after

                      oTab.Range.Next.InsertBefore sTab & vbCrLf & vbCrLf

to give the paragraph a caption style...

For some reason, when I try to use

                      oTab.Range.InsertCaption ...

it errors with 'Command Failed'.  I think it may be a bug but I'm not sure...

HTH

J.
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:etdwh
ID: 12413787
Thanks for the reply. I shall try this out.

From what i understand from the code, it numbers every table in the document.
Is there a way to limit this ?

There were some parts in the document (section 3) i used tables as placeholders and to partition the page into several parts.

Or is there a way to apply this macro only to a selection of tables ?
0
 
LVL 16

Accepted Solution

by:
jimbobmcgee earned 500 total points
ID: 12415377
As it stands, the macro I wrote above will do it to all tables, no exceptions.  You _could_ limit it, but it would require something common about all the 'placeholder' tables.  Then you could limit so it does not touch those tables.  The following change will make the macro only work for tables that have an outer border:

    Sub InsertTableNumber()
   
        Dim oSec As Word.Section
        Dim oTab As Word.Table
        Dim oPar As Word.Paragraph
       
        For Each oSec In ActiveDocument.Sections
       
            iTab = 0
           
            For Each oTab In oSec.Range.Tables
           
                If oTab.Borders.OutsideLineStyle <> wdLineStyleNone Then     '<-- IF TABLE'S OUTER BORDER IS 'NONE' DO THE COUNT
               
                    iTab = iTab + 1
                    sTab = CStr("Table " & oSec.Index & "." & iTab)
                   
                    oTab.Range.Next.InsertBefore sTab & vbCrLf & vbCrLf
                    oTab.Range.Next.Style = "Caption"
               
                End If
           
            Next oTab
       
        Next oSec
   
    End Sub


HTH

J.
0
 
LVL 3

Expert Comment

by:MBarber1957
ID: 12420035
You could use Insert->Field->Categories: Numbering->Section to put the Section number into your Table. The Table number could be an Autonum field. One downside to this is that, if you change the position or quantity of tables in the document, you will need to remember to update the field references; even here though you could turn the Update Fields option on in Tools->Options->Print->Update Fields which will automatically renumber all fields prior to printing. This way you do not need the Caption facility at all.
0
 

Author Comment

by:etdwh
ID: 12420552
I shall accept jimbobmcgee's answer. Not only does this work perfectly, i could add more conditions later, such as skip sections, even caption other objects. If what works in VB works here too, i could add input boxes for this...i guess

MBarber1957, thanks for the suggestion, but your idea wont work, because if its not a caption, i cant create a List of Figures and Tables later. Futhermore, captions can also have a specific style for it. But just for the sake of numbering the tables, your method does work.

But i prefer jimbobmcgee macro because its automatic. Drawback, cant update the fields if you add more tables. Only option, select all captions starting with Table, delete it, and run macro again

Thanks for the solution
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12421024
Thanks for the points.  It should be worth noting that my code doesn't actually create captions, it justs makes a bit of text after the table and makes it look the same as all other captions.  I don't know if this will work when you come to create your contents page.

If anyone can give the correct implementation of the InsertCaption method (and why it just says Command Failed for me), for use in the code I have posted above, I will award them 200 points, myself...

J.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
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 …

610 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