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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where is the insertion point in Word? 2

Status
Not open for further replies.

cthaxter

Programmer
Aug 2, 2001
71
US
I am trying to execute a Selection.Find in MS Word and then return the exact location relative to the beginning of the document.

Let's say I have two instances of the word "computer" in my text, and two instances of the term "computing". I want to find the first instance of any of those, and highlight it or somehow mark it. I do NOT want to find other forms of the word, such as "computation".

My approach is to do a CTRL Home and then find the first instance of "computer", and then CTRL Home again and find the first instance of "computing". Let's say it finds both. How do I know which one is closer to the beginning of the document?

The status bar in Word tells me which page I'm in, which section, how many vertical inches from the top, and which line and column I'm in. The key may be those Ln and Col values. But how can I access those programmatically?

Or can anyone think of an alternate solution?

 
the selection object has a .Start property
or you could use the .Information property

from VBA help (Word 97):

Information Property

Returns information about the specified selection or range. Read-only Variant.
Syntax

expression.Information(Type)

expression Required. An expression that returns a Range or Selection object.

Type Required Long. The information to return. Can be one of the following WdInformation constants:

· wdActiveEndAdjustedPageNumber Returns the number of the page that contains the active end of the specified selection or range. If you set a starting page number or make other manual adjustments, returns the adjusted page number (unlike wdActiveEndPageNumber).
· wdActiveEndPageNumber Returns the number of the page that contains the active end of the specified selection or range, counting from the beginning of the document. Any manual adjustments to page numbering are disregarded (unlike wdActiveEndAdjustedPageNumber).

· wdActiveEndSectionNumber Returns the number of the section that contains the active end of the specified selection or range.
· wdAtEndOfRowMarker Returns True if the specified selection or range is at the end-of-row mark in a table.
· wdCapsLock Returns True if Caps Lock is in effect.
· wdEndOfRangeColumnNumber Returns the table column number that contains the end of the specified selection or range.

· wdEndOfRangeRowNumber Returns the table row number that contains the end of the specified selection or range.
· wdFirstCharacterColumnNumber Returns the character position of the first character in the specified selection or range. If the selection or range is collapsed, the character number immediately to the right of the range or selection is returned (this is the same as the character column number displayed in the status bar after "Col").

· wdFirstCharacterLineNumber Returns the line number of the first character in the selection. If the Pagination property is False or the Draft property is True, returns  – 1.
· wdFrameIsSelected Returns True if the selection or range is an entire frame or text box.
· wdHeaderFooterType Returns a value that indicates the type of header or footer that contains the specified selection or range, as shown in the following table.

Value Type of header or footer
 – 1 None (the selection or range isn't in a header or footer)
0 (zero) Even page header
1 Odd page header (or the only header, if there aren't odd and even headers)
2 Even page footer
3 Odd page footer (or the only footer, if there aren't odd and even footers)
4 First page header
5 First page footer
· wdHorizontalPositionRelativeToPage Returns the horizontal position of the specified selection or range; this is the distance from the left edge of the selection or range to the left edge of the page, in twips (20 twips = 1 point, 72 points = 1 inch). If the selection or range isn't within the screen area, returns  – 1.
· wdHorizontalPositionRelativeToTextBoundary Returns the horizontal position of the specified selection or range, relative to the left edge of the nearest text boundary enclosing it, in twips (20 twips = 1 point, 72 points = 1 inch). If the selection or range isn't within the screen area, returns  – 1.

· wdInClipboard Returns True if the specified selection or range is on the Macintosh Clipboard.
· wdInCommentPane Returns True if the specified selection or range is in a comment pane.
· wdInEndnote Returns True if the specified selection or range is in an endnote area in page layout view or in the endnote pane in normal view.
· wdInFootnote Returns True if the specified selection or range is in a footnote area in page layout view or in the footnote pane in normal view.

· wdInFootnoteEndnotePane Returns True if the specified selection or range is in the footnote or endnote pane in normal view or in a footnote or endnote area in page layout view. For more information, see the descriptions of wdInFootnote and wdInEndnote in the preceding paragraphs.
· wdInHeaderFooter Returns True if the selection or range is in the header or footer pane or in a header or footer in page layout view.

· wdInMasterDocument Returns True if the selection or range is in a master document (that is, a document that contains at least one subdocument).
· wdInWordMail Returns a value that indicates the WordMail location of the selection or range, as shown in the following table.

Value WordMail Location
0(zero) The selection or range isn't in a WordMail message.
1 The selection or range is in a WordMail send note.
2 The selection or range is in a WordMail read note.
· wdMaximumNumberOfColumns Returns the greatest number of table columns within any row in the selection or range.
· wdMaximumNumberOfRows Returns the greatest number of table rows within the table in the specified selection or range.
· wdNumberOfPagesInDocument Returns the number of pages in the document associated with the selection or range.
· wdNumLock Returns True if Num Lock is in effect.
· wdOverType Returns True if overtype mode is in effect. The Overtype property can be used to change the state of overtype mode.

· wdReferenceOfType Returns a value that indicates where the selection is in relation to a footnote, endnote, or comment reference, as shown in the following table.

Value Description
 – 1 The selection or range includes but isn't limited to a footnote, endnote, or comment reference.
0 (zero) The selection or range isn't before a footnote, endnote, or comment reference.
1 The selection or range is before a footnote reference.
2 The selection or range is before an endnote reference.
3 The selection or range is before a comment reference.
· wdRevisionMarking Returns True if change tracking is in effect.
· wdSelectionMode Returns a value that indicates the current selection mode, as shown in the following table.

Value Selection mode
0 (zero) Normal selection
1 Extended selection ("EXT" appears on the status bar)
2 Column selection. ("COL" appears on the status bar)
· wdStartOfRangeColumnNumber Returns the table column number that contains the beginning of the selection or range.
· wdStartOfRangeRowNumber Returns the table row number that contains the beginning of the selection or range.
· wdVerticalPositionRelativeToPage Returns the vertical position of the selection or range; this is the distance from the top edge of the selection to the top edge of the page, in twips (20 twips = 1 point, 72 points = 1 inch). If the selection isn't visible in the document window, returns  – 1.

· wdVerticalPositionRelativeToTextBoundary Returns the vertical position of the selection or range, relative to the top edge of the nearest text boundary enclosing it, in twips (20 twips = 1 point, 72 points = 1 inch). This is useful for determining the position of the insertion point within a frame or table cell. If the selection isn't visible, returns  – 1.
· wdWithInTable Returns True if the selection is in a table.
· wdZoomPercentage Returns the current percentage of magnification as set by the Percentage property.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top