LINEREF ...Where is it?

R

Rob

Help, It is easy enough to discover the page number of a bookmark using PAGE
or PAGEREF (w/o even programming). If Line Number is turned on for the active
document how does one find the line number of the bookmark on a given line?
On several proposal documents we must show the page and line reference of the
related item. To do this, we place a bookmark attached to the selected text
or object, then use the PAGE or PAGEREF field to get the page#, but we have
to type the line number in manually......isnt this supposed to be helping us
to not crane our necks at a monitor...?

Sincerely cross(eyed)
Rob
 
D

Doug Robbins - Word MVP

There is no LINEREF field in Word.

With the selection where you want to insert the line number, you could run a
macro containing the following code:

Selection.InsertBefore
ActiveDocument.Bookmarks("test").Range.Information(wdFirstCharacterLineNumber)

Which could be modified so that you were presented with a list of the
bookmarks to choose from rather than having a particular bookmark name hard
coded into the code. HOWEVER, it is probably NOT worth the effort as the
number that is inserted will not update if the position of the bookmark on
the page changes.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Rob

Hi Doug, and thanks for posting. I appreciate your occupation, my experience
is on the embedded microcontroller side. I am trying to help someone work
through this problem for their company (unpaid). My coding experience is
limited
in the Office arena, but have been doing some C# and a lot of Ansi C for
8/16 bit
micros....

I think that you may have given me the means to an end, but let me explore
this for the sake of all who might happen to be looking for the same
information (I know there have been at least three of four earnest
investigators that are struggling with this).

First, I want to clarify what I think Linenumber is:

I have a Word 2003 document that I have populated with text and pictures.

Using Word 2003 when I turn on the word count toolbar, and select Lines,
then click Recount, this toolbar item tells me that my document has 207 lines.

Using Word 2003 when I go to Page Setup, select the Layout tab, click on
Line Numbering, and turn it on so that the first number is 1, and the
numbering is continuous, the last line number (printed in the left most
column) in my document is 131.

So right off the bat, I have an issue with the Word Count toolbar..but hey,
I didnt pay anything for that little toolbar....

What I need to be able to display in a table, is the line number (of a
particular bookmark or other special field code) that is shown in the left
column when Line Numbering is turned on.

I think you are telling me that if I select a bookmark (using a macro), that
I can get the line number (I am hoping that this would be the same line
number that is presented by the Line Numbering as opposed to the Word Count
toolbar) from the range properties of the first character of the bookmark.

It is acceptable that the bookmark may move from one line to another,
because what I need is to be able to display in a table (somewhere in the
same document), the page# and the line# of the first character of the
bookmark and be able to update the field or value either through F9 or a
macro.

If in fact the absolute line number (I am referring to the WordCount
toolbar count of lines in the document) is part of the property of the range
information as opposed to the line numbering line number, then is there a way
to convert between absolute line numbers and the Line Numbering line numbers?
It would seem possible that a macro or VB module could parse the document,
and not increment the line number when the absolute line is occupied by a
figure or table... I am guessing more than a few lines of code to do this...

If you have the time, perhaps just correcting my use of terminology so that
I might be able to search the correct terms and get a solution out there. If
you have more than that well you might just be a hero..

Cheers,
Rob
 
D

Doug Robbins - Word MVP

Doing a bit of testing, the code returns the line number corresponding to
the line numbering displayed as a result of application of line numbers to
the document via the Page Setup menu item, PROVIDED that the line numbering
is set to restart from 1 for each page. That is, it returns the number of
the line on that page, not from the beginning of the document.

It will not update using F9; it would be necessary to re-run the macro if
the line number has changed.

Another thing to be aware of is that the Page Setup Line Numbers are not
applied to lines withing a table, but the number that the code returns DOES
take into account the lines within a table. As a result, it won't work for
you on any page on which there is a table before the item whose Line Number
you want to reference.

If you are going to be needing to update the Line Number references, it
would be best to use

Selection.Text =
ActiveDocument.Bookmarks("test").Range.Information(wdFirstCharacterLineNumber)

and when updating the number, select the previously inserted number, so that
it is replaced by the new Line Number.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Rob

Hi Doug (Thank You Doug Robbins!);

Confirmed the behavior that it does not make any difference how the page
setup Line Number is actually applied (enabled or not), the results are
always the same. I prepended

ActiveDocument.Bookmarks("Test003").Range.InformationwdActiveEndPageNumber)
& "/" &
ActiveDocument.Bookmarks("Test003").Range.Information(wdFirstCharacterLineNumber)

to get the desired formatted page/linenumber. But is there a case where the
bookmark end is on the next page, then the page number is wrong...I didn't
see a property to get the page number of the first character in the bookmark.
Is there something for that or I suppose I should use the PAGE field code for
that. (I hate to mix code with fields that will update from F9, but I suppose
I could force a F9 update in the macro?)

Alternatively, I could recommend bookmarking only the first word...

Also, any ideas on Office 2007 and beyond behavior?

Rob
 
D

Doug Robbins - Word MVP

My testing was done in 2007 and there is no change in that version from
earlier versions. I don't have any information on future versions.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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