Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page Number Information

Status
Not open for further replies.

noHandlebars

Technical User
Jun 25, 2008
46
US
In microsoft word, I'm generating a table of contents, and i was wondering if it was possible to do a find for a certain title in the document and get the information for what page of the document it is on. Then have that information put onto the table of contents page. Any suggestions?
 



Hi,

TOC data is a result of your HEADING Style structure.

If you have data that is NOT a HEADING Style, but you need to refrence it, consider using an INDEX in addition to the TOC.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I'm not really sure how to do that. I guess I'm asking if it's possible to do a FIND in a document and determine what page of the document that the find takes you to.
 




You don't have to do a FIND. The built-in functionality (CTRL + Click to follow link) does that in the TOC.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I'm not sure what your talking about. The document I am working with has a pre-made table of contents in it, but where the page numbers would be there are just "XX". I need to replace the "XX" with the correct page numbers where each section of the document is located.

Here is an example:

B: OPERATIONS XX
C: DESIGNS XX
D: REGULATIONS XX


 




"The document I am working with has a pre-made table of contents "

Was this TOC MANUALLY constructed, or was it construced using Insert > Reference > INDEX & TABLES???

If the latter, you will be able to hover over a TOC entry and see a popup message regarding CTRL + Click to follow link. You will also be able to UPDATE the TOC by right-clicking in the TOC.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
No it was manually constructed which is probably why i don't know what you are talking about.
 




Why was it constructed the HARD way? Really dumb and extremely inflexible!

Use Word's features. They're Grrrrrreat!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Ok well since it wasnt made using words features is there any way to get the page number info using like a FIND or something else
 
noHandlebars, it is MUCH MUCH better to use Word's Table Of Contents feature. Manually creating a ToC is a pain in the butt, and is very prone to errors - a minor change in text can change the page number...and there you go, having to manually change the ToC.

Doing a Find as you describe is also quite prone to errors, as you would have to built very tight logic to make sure the XX is the correct page. What if you want page 23 to be with (for example) REGULATIONS.

This could be done of course, but if you use "23" as Find, then it is going to find ALL instances of "23", and if you have any "23" elsewhere in the document, how does your macro know that one should NOT be used, but THIS one - the one for the page you actually want - should be used?

Pain in the butt.

This is the whole purpose of generated ToC. It works very well, and you should start using it. If you do (and use it properly), your problem simply goes away. The ToC will generate the correct page number for you.

Not only that, but the default setting (as was mentioned) sets the ToC entries as hyperlinks, and you can click on a ToC item, and jump to that page. Very handy.

faq219-2884

Gerry
My paintings and sculpture
 
I don't want to make hyperlinks, I want to be able to determine on what page the "REGULATIONS" section would start. Then replace the "XX" with that page number.

This will need to be run on multiple documents. Each document is going to have different page numbers where each section starts. It is not possible to utilize the word TOC, all the documents are already made.
 
Each document is going to have different page numbers where each section starts. It is not possible to utilize the word TOC, all the documents are already made. "

This is simply not accurate.

As a test, I just now removed the Table of Contents from 61 documents in a folder. Saved them. The ToC are gone. The documents are "already made"....but now do not have a ToC. The section breaks, page numbering, is different between documents.

Next, I ran code to process all 61 documents, generating new ToC for all of them.

Time to process all 61 documents: 1m 34s

Badda bing, badda boom.

If you do not want to use a native feature and functionality that will make your documentation better, that is certainly your choice.

I just wish to point out: "Each document is going to have different page numbers where each section starts. "

With a generated ToC, this is absolutely, and totally, irrelevant. That is the point of a generated ToC, that it generates the correct ToC regardless of what the page number is.

If you insist on doing it the hard way: "is there any way to get the page number info using like a FIND or something else "

The answer is a qualified yes. However, the problem is - as I have already stated - getting the logic tight. It will not be horribly difficult, but it certainly would not be trivial.

search for your text (REGULATIONS, etc.) (not hard)
find the page number (not hard)


....now what?

How do you get THAT page number to replace the XX for REGULATION...and not the XX for DESIGNS? How do you get that page number back to the REGULATIONS manually typed into the "table of contents"?

I can think of a few possible routes, but ALL of them are ugly, and prone to errors.

Which is why professional document writers use generated ToC. You never have to think about getting the page numbers. If you add something to the document that may change the numbers, you simply right click the ToC...and select Update.

Done.


Good luck.

faq219-2884

Gerry
My paintings and sculpture
 
Hi noHandlebars,

With what Style(s) is/are your subject/chapter headings in the body of the document formatted?

If they're formatted using one or more of Word's Heading Styles, then creating a dynamic Table of Contents, with page numbers, is as simple as using Insert|Field > Index and tables > TOC and choosing the appropriate options.

If they're NOT formatted using one or more of Word's Heading Styles, then I suggest doing so now. Then follow the above steps. It's probably even less work than developing and testing a macro to do what Word is already designed to do well.

Cheers

[MS MVP - Word]
 
Could you just tell me how to get the page number information.

I understand that using the Word TOC would be more efficient but I don't have authorization to change the format of the documents.
 
noHandlebars,

That IS how to get the page number information. There is no need to change any formatting - if the most appropriate heading styles are formatted differently, then change their formatting.

Learn how to use Word instead of asking others to waste time & effort building workarounds for people who won't. It's not difficult and, once its learnt, could improve productivity quite a bit.


[MS MVP - Word]
 
Ok, here is a way that you can continue to be dense regarding the TOC while making Skip and Fumei happy by using some native word functionality.

Create an index using a concordance file. The entries in the concordance file will be the words that are currently manually typed in to your TOC.

This will give you a wonderful list of each and every page where each word is found.

Why can't you get authorization to do something more efficiently? This does not speak well of your bosses or company.
 
I do not think that will work.

noHandlebars: "Could you just tell me how to get the page number information. "

Yes. Here is how.
Code:
Dim j As Long
With Selection.Find
   .Text = "REGULATIONS"
   .Execute
   If .Found Then
      j = Selection.Information(wdActiveEndAdjustedPageNumber)
   End If
End With
j is the page number of the found "REGULATIONS".

That is exactly what you asked for. As you have utterly ignored anything else, specifically my comments regarding getting the logic tight, and how do you get that number back to your manual ToC...good luck.

BTW: Of course the first number it will get...will be the page number of "REGULATIONS" on your maually typed ToC. So you will have to code it so it ignores that (presumably) first Found, and go on to the next one (also presumably the one you want). I will not help with doing that.

But that IS exactly how to get the page number information for the text "REGULATIONS". Which is what you asked for.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top