Defining a range in a Word Document

Posted on 2005-04-28
Last Modified: 2010-04-23
Hello Experts:

I have successfully create an object to open an existing word document, setup a command bar and created buttons on the command bar that interact with the document; However, I am having one problem.  I need to determine the current location of the cursor so that I can create a range to insert some information.

I have an object called Worddoc that represents the currently opened document.  I also have an variable that is used to reference a range within that document .. wrdRange.

I'll be glad to award 1000 points to the individual that helps me solve this issue.

Thanks ...

I'm currently coding this for Word 2000.
Question by:escheider
    LVL 8

    Expert Comment

    I don't have a lot of experience in this area, but my best guess is that it is unikely you can get that info. I am assuming that the document object represents a word document. The cursor however, is a function of Microsoft Word.

    In other words, MS Word is the editor, and it maintaines the location of the cursor. That cursor location isn't "saved" when you save the document. Close the document and open it again, the cursor goes back to the beginning.

    So if your document object represents a word doc, then I don't see how it could determine where the cursor is in the editor.

    Of course, I could be completely wrong... :)

    Perhaps you could implement some sort of method such as having the user insert a custom tag in the Word doc, and then searching the doc to locate that tag, and go from there?
    LVL 4

    Author Comment

    Even if I inserted the custom tag, I'd like to do it by clicking the button on the commandbar that I have created; Therefore, I would still need to know the location of the cursor to do this.   I am using this application to build templates and the commandbar is used to complete this process.
    LVL 34

    Accepted Solution

    I no longer have Word 2000, but in an active MSWord document in Word 2002 the position of the cursor seems to be derivable from the start and end properties of the Selection object.

    LVL 4

    Author Comment

    Thank you Sancler .. this is exactly what I needed to define the location of the cursor, even in Word 2000.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now