How can I know current insert position?

H

huh

I'm programing character count addin. It count from document start to current
insert position (cursor position) not document end.

Does it exist api - get current insert/cursor position?
 
J

Jezebel

The current cursor position is the Selection object. So the 'cursor
position' you want is presumably is Selection.Start. The number of
characters in the document up to the cursor is given by

ActiveDocument.Range(0, Selection.Start).Characters.Count
 
H

huh

Thanks a lot Jezebel. It's working.

In addition, I add next routibe to confirm insert position.

if(Selection.Type == Word.WdSelectionType.wdSelectionIP) {
currentEnd = Selection.End;
}

But I think 'Range.Count' property is something wrong. It count everything
between start and end range.(If I make [2,2] table - table is blank -, count
property increse 6. If I add image, count property increse.)

I have used 'Range.ComputeStatistics()'. It was accuracy more than
Range.Count but more slow and insert position in Word is dismised. ;)

Somebody know more accuracy and fast method to count characters?
 
J

Jezebel

You need to define your terms. Range.Count includes a lot of things that you
wouldn't want to count as characters: eg paragraph marks, end-of-cell
markers in tables, field codes, etc. What are you actually trying to count,
for what purpose?

What's wrong with Range.Characters.Count?





huh said:
Thanks a lot Jezebel. It's working.

In addition, I add next routibe to confirm insert position.

if(Selection.Type == Word.WdSelectionType.wdSelectionIP) {
currentEnd = Selection.End;
}

But I think 'Range.Count' property is something wrong. It count everything
between start and end range.(If I make [2,2] table - table is blank -,
count
property increse 6. If I add image, count property increse.)

I have used 'Range.ComputeStatistics()'. It was accuracy more than
Range.Count but more slow and insert position in Word is dismised. ;)

Somebody know more accuracy and fast method to count characters?

Jezebel said:
The current cursor position is the Selection object. So the 'cursor
position' you want is presumably is Selection.Start. The number of
characters in the document up to the cursor is given by

ActiveDocument.Range(0, Selection.Start).Characters.Count
 
H

huh

My boss order to me ;-(, make addin that count characters between start to
current insert position periodically.

characters mean 'characters(with space)' value in statistic dialog that is
built-in Word 2007.

Jezebel said:
You need to define your terms. Range.Count includes a lot of things that you
wouldn't want to count as characters: eg paragraph marks, end-of-cell
markers in tables, field codes, etc. What are you actually trying to count,
for what purpose?

What's wrong with Range.Characters.Count?





huh said:
Thanks a lot Jezebel. It's working.

In addition, I add next routibe to confirm insert position.

if(Selection.Type == Word.WdSelectionType.wdSelectionIP) {
currentEnd = Selection.End;
}

But I think 'Range.Count' property is something wrong. It count everything
between start and end range.(If I make [2,2] table - table is blank -,
count
property increse 6. If I add image, count property increse.)

I have used 'Range.ComputeStatistics()'. It was accuracy more than
Range.Count but more slow and insert position in Word is dismised. ;)

Somebody know more accuracy and fast method to count characters?

Jezebel said:
The current cursor position is the Selection object. So the 'cursor
position' you want is presumably is Selection.Start. The number of
characters in the document up to the cursor is given by

ActiveDocument.Range(0, Selection.Start).Characters.Count






I'm programing character count addin. It count from document start to
current
insert position (cursor position) not document end.

Does it exist api - get current insert/cursor position?
 

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