Code that will auto-number tables in report?

E

Ed

I think people are about done messing with the report "I" am writing. Now
it's time to go through and make all the changes work. One issue is tables
added and deleted. Is there a way to go through the document to pick up the
"number" of each table, and use that in the table title? For instance, the
first table would be:
"TABLE 2.45.{table number(1)}: Table Title"
^p
***table(1) goes here ***

and so forth?

Ed
 
E

Ed

Barring an easier FieldCode answer or such, how does this code outline
sound?

Dim i, noTbl as Integer
noTbl = Tables.Count
i = 1

Loop
Select Table(i)
Find/Replace
Search Up
Text:"Table 2.45.XX"
ReplaceWith:"Table 2.45." & i
i = i + 1
Do Until i > noTble

Workable? Too much? Hidden traps for the unwary?

Ed
 
S

Suzanne S. Barnhill

I'm not entirely clear on what you're trying to do, but are we to understand
that it is something that could not be accomplished with Word's built-in
captions using "Include chapter number"?

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://www.mvps.org/word
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

Jay Freedman

Hi, Ed,

Use a SEQ field in each table title. Look at the Help topic, which
explains about using a sequence name in the field code.

Forget the macro code. You'd have to rerun it every time you add or
delete or move a table, and Murphy's law says you'd forget to do it
just when it's most critical...
 
E

Ed

Y'know, I've used Word for years, producing reports with tables and figures
(and bears for editors, oh my!), and *never* knew about Captions! I have
spent entire days going over a document with no other purpose than to ensure
every table and every figure is numbered in the correct sequence. I guess
it just might pay to know something about my tools besides how to
double-click an icon and start typing! 8>\

Thanks for replying, Suzanne. I'll work on this (maybe even read the Help
files!).

Ed
 
E

Ed

Jay, I never even knew this existed! And I'm betting a lot of my co-workers
don't as well! I will play with this, and yell back if I get into trouble.

Thanks so much.
Ed
 
S

Suzanne S. Barnhill

A good example of why my first advice to new Word users is "Be curious:
explore all Word's menus and dialogs. Even if you don't know what a feature
is for, you are more likely to think of it when you need it than if you've
never seen it and don't know it exists." You would (or perhaps would not) be
amazed by the number of questions we see asking, "Is there a way to create
footnotes so that they will renumber when I insert a new one in the middle?"
or wanting to know how to set leader tabs (though users don't usually know
that term or even that that's what they need) for TOCs created by hand. Etc.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://www.mvps.org/word
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
E

Ed

Well, it looks very nice so far. A couple of questions, though.

(1) Can I insert the caption and have it pick up the formatting of the text
around it? Or is there an option to set the formatting?

(2) In my reports, the table is always referred to in the preceding
paragraph - "as shown in Table XXX" - as well as captioned. Can I have the
same sequence number show up in both the paragraph and the caption? I
couldn't make that work.

Ed
 
E

Ed

Sounds like a good subject for a book: "Word's Most Overlooked Features and
the Common Problems They Solve". I know I would buy it! Heck - I still
don't use styles and templates - yet!

Ed
 
S

Suzanne S. Barnhill

On the off chance that you're actually using Word's built-in captions and
not inserting the SEQ fields manually:

You can modify the Caption paragraph style, or you can apply a different
style to the caption after it's inserted (but be aware that Word looks for
the Caption style when creating a Table of Figures). You can insert
cross-references to caption numbers: Insert | Cross-reference (Insert |
Reference | Cross-reference in Word 2002 and above) to Table, choosing from
among the options to display the number with or without "context" (you
figure it out) or the caption text or whatever. Cross-references will adopt
the formatting of surrounding text.

If you insert the SEQ fields manually (with a custom sequence identifier),
you won't find your sequence identifier listed in the cross-reference dialog
as you will if you've used a built-in caption with a custom label. But if
you've used one of the existing labels (which would include Table) in a
hand-built SEQ field, then you get to use Word's built-in cross-reference
feature easily.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://www.mvps.org/word
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Ed said:
Well, it looks very nice so far. A couple of questions, though.

(1) Can I insert the caption and have it pick up the formatting of the text
around it? Or is there an option to set the formatting?

(2) In my reports, the table is always referred to in the preceding
paragraph - "as shown in Table XXX" - as well as captioned. Can I have the
same sequence number show up in both the paragraph and the caption? I
couldn't make that work.

Ed
 
E

Ed

Thank you, Suzanne. You've got to write that book!

Ed

Suzanne S. Barnhill said:
On the off chance that you're actually using Word's built-in captions and
not inserting the SEQ fields manually:

You can modify the Caption paragraph style, or you can apply a different
style to the caption after it's inserted (but be aware that Word looks for
the Caption style when creating a Table of Figures). You can insert
cross-references to caption numbers: Insert | Cross-reference (Insert |
Reference | Cross-reference in Word 2002 and above) to Table, choosing from
among the options to display the number with or without "context" (you
figure it out) or the caption text or whatever. Cross-references will adopt
the formatting of surrounding text.

If you insert the SEQ fields manually (with a custom sequence identifier),
you won't find your sequence identifier listed in the cross-reference dialog
as you will if you've used a built-in caption with a custom label. But if
you've used one of the existing labels (which would include Table) in a
hand-built SEQ field, then you get to use Word's built-in cross-reference
feature easily.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://www.mvps.org/word
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
S

Shauna Kelly

Hi Ed
I still
don't use styles and templates - yet!

Let me take you up on that<g>. Everyone use styles and templates,
whether or not they have made conscious choices about them. Every
document is based on a template. If you haven't explicitly chosen a
template, then all your documents are based on normal.dot.

Using the defaults, all your text is in style Normal, headers are in
style Header, footers are in style Footer, ToCs use the TOC styles,
captions use Caption style etc etc.

There's no avoiding them, which is why I reckon it's worth learning how
to control them!!!!

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Melbourne, Australia
 
E

Ed

I'm just feeling really small right now. I went out and bought Word 2000
Developer's Handbook because there were some sticky VBA things I was dealing
with. I was feeling good that I now have all this information about the
objects and methods and such. Now I realize I should have bout something
like Word for Dummies a few years ago, and I'd be much farther ahead now!
Like not trying to cook up a macro to do what Word's built-in stuff will
already do - if only I had known how! I just had to manually renumber 2
reports, one with 28 tables and one with 45, that would have been a snap
with a few captions, style tags, etc. I know I use them - like I drive my
car, but I can't program the radio! (But I have a teenager! 8>} )

Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top