Include Section number in captions

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
etdwhAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AntonioPCommented:
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
jimbobmcgeeCommented:
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
jimbobmcgeeCommented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

etdwhAuthor Commented:
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
jimbobmcgeeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MBarber1957Commented:
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
etdwhAuthor Commented:
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
jimbobmcgeeCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.