Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting the current Sentence position

Posted on 2002-07-17
10
Medium Priority
?
211 Views
Last Modified: 2010-05-02
I have the following code.

Dim wrdApp As Word.Application
Dim appWord As Word.Document

wrdApp.Selection.GoTo wdGoToLine, wdGoToFirst  

and i open appWord with the wrdapp.open

With wrdapp.Selection.Find
    .Forward = True
    .Wrap = wdFindStop
    .Text = "$"
    .Execute
   End With

When it finds the occurance of the $, i need to findout what line number it is on, how can i do that?

appword.Sentences(10) is line 10 (the line number i want)
but i can't find anything that will return to me that current position or line number.

Thanks.
masterofhisdomain
0
Comment
Question by:masterofhisdomain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:damion69
ID: 7160726
0
 

Author Comment

by:masterofhisdomain
ID: 7160815
Unfortunately, that is only for controls, the API has to have a handle in order to find the position based of the cursor position, which is not going to work in my case.

This application i am building has no forms or controls.

I have opened the word document, and have found the character i am looking for, now i just need what line number it is on.

Thanks tho, it will bue useful in the future.

Any other ideas?
0
 
LVL 46

Expert Comment

by:aikimark
ID: 7161270
What do you mean by line number?

Do you need the postition relative to the page or the start of the document/story?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 43

Expert Comment

by:TimCottee
ID: 7161607
masterofthisdomain, I am more than happy to be proved wrong in the following statement but as far as I am aware there is no method within Word to access the Line/Column position of a character. The information that is displayed within the status bar has to be calculated somehow but this is not apparently available to mere mortals using the application.
0
 
LVL 2

Accepted Solution

by:
damion69 earned 200 total points
ID: 7162069
Ok... Here is another piece of code that does that...

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=441&lngWId=1
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7162095
well damion69, not quite. This code simply retrieves the number of lines in total in a document using an antiquated and non-recommended method so it unfortunately not going to help in this situation.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 7162154
Word will easily tell you what line the cursor is on, but the line number is relative to the page:
selection.Information(wdFirstCharacterLineNumber)

Also, there is a method that will tell you how many total lines there are in the document:
activedocument.ComputeStatistics(wdStatisticLines)

I haven't found a method or property that will tell you the line number relative to the start of the story or document.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 7162161
masterofhisdomain,

What are you trying to do that you need this line number data?
0
 

Author Comment

by:masterofhisdomain
ID: 7162226
This is what i was looking for, it led to the answer.  Version 6 uses a different way of doing it.

I ended up adding this to get the current line

Dim Rc as integer

Rc = wrdApp.Selection.Information(wdFirstCharacterLineNumber) - 1

Using the Word objects, when i saw you could do appword.sentences(13) to get line 13 , i knew there had to be a way to get to the current sentence when coming back from a find.  Thank You.
0
 

Author Comment

by:masterofhisdomain
ID: 7162244
Thanks aikimark for your answer, i did not refresh after getting damion69s answer, but after scanning the help file with his answer, found the Info method, and had tried it before, but either missed the line number one or discounted it from being what i was looking for.

I need the line number, because from the first find on, i will be accessing each sentence seperately to do check to see if the line gets added to an array or that sentence sent to a file.

Thanks for all your help.
Masterofhisdomain
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question