Add Style or other for TOC after the fact

E

Ed

I have a report doc that needs the section page numbers put into a table of
contents. Because these things get passed around and stuff put in from
emails, web pages, and several different users, the whole thing is formatted
in one style - Normal - and formatting (usually only bold and/or center)
applied directly to the text.

Now that I'm nearing the finish, I can either go back through several
hundred pages and pick out all the page numbers to manually enter them, or I
can figure out how to apply a Style or whatever else might be picked up by
Word's numbering to the appropriate text without losing applied formatting.
Then I need to grab that page number and put it into the correct spot in the
already-created Table of Contents.

Where should I start, now that I'm almost done?

Ed
 
C

Charles Kenyon

You have a dog's breakfast of a document. Sorry.

Look into heading styles. Apply these as appropriate, at least to things you
want in your table of contents. You can change the formatting of your
heading styles so they look the way you want.

If you are using Automatic numbering, be sure to set it up properly, don't
just go pushing buttons. See: How to create numbered headings or outline
numbering in your Word document
http://www.shaunakelly.com/word/numbering/OutlineNumbering.html.

Once you have applied the appropriate styles to your headings, put your
insertion point where you want your table of contents and have Word generate
it. Insert > Reference > Tables and Indexes

You can pick which heading styles are shown and change how your TOC looks by
adjusting the settings.
http://addbalance.com/usersguide/complex_document.htm
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
E

Ed

You have a dog's breakfast of a document. Sorry.
Thank you - I'm not high enough up the food chain here to say that! 8>)

I was thinking more of a macro that would allow me to either apply a style
and then paste into it the formatting of the text I'm applying it to, or
that would drop in some field, bookmark, or other Word object that could be
iterated and would allow me to pick up the page number. The TOC is already
set into an actual table - I could go back to that table and run a macro
that would iterate through the objects or Find the Style, grab the page
number at each position, then increment down the table column to insert the
page number.

It might take just as long coding that and setting it up as it would to
manually insert the page numbers, but coding the macro would be more fun!
What do you think?

Ed
 
H

Helmut Weber

Hi Ed,

at a very long shot,

you could record properties of the selection,
like font-properties,
by selecting a piece of text, call the format-font dialog,
hit [return], apply the so determined formatting,
which doesn't do anyhting,
search another piece of text, or move the cursor to it,
and hit [F4].

In Code:
' formatting was recorded before!

Sub Macro22()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "ck"
While .Execute
rDcm.Select
Repeat (1)
Wend
End With
End Sub

.... which didn't work without selection, alas.

I guess, one could record paragraph formatting
and formatting of bullets and numbering in the same way,
and apply it programmatically to found pieces of text.


HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
E

Ed

I thought about using CopyFormat and PasteFormat - select the text, Copy
Format, set it to a Style name, then PasteFormat to return it to what it
was. The other half of the problem is how to capture the page number of the
text. The Table of Contents is already in a table. I could iterate through
the table, select the section title text in a cell, Find the text in the
document with the designated Style, get the page number and write it into
the table at same row, next column.

Returning the page number was the big problem. The only thing I could thing
of was to collapse my Find selection, insert a PageNumber field, get the
returned number, then delete the field. Do-able, and no problem for VBA -
just a bunch of extra junk and possibly causing doc repagination and slowing
things down.

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