Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7420173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:11:40+00:00 2026-05-29T08:11:40+00:00

Is it possible to get text (line or sentence) from a given line number

  • 0

Is it possible to get text (line or sentence) from a given line number in MS Word using office automation? I mean its ok if I can get either the text in the given line number or the sentence(s) itself which is a part of that line.

I am not providing any code because I have absolutely no clue how an MS Word is read using office automation. I can go about opening the file like this:

var wordApp = new ApplicationClass();
wordApp.Visible = false;
object file = path;
object misValue= Type.Missing; 
Word.Document doc = wordApp.Documents.Open(ref file, ref misValue, ref misValue,
                                           ref misValue, ref misValue, ref misValue,
                                           ref misValue, ref misValue, ref misValue,
                                           ref misValue, ref misValue, ref misValue);

//and rest of the code given I have a line number = 3 ?

Edit: To clarify @Richard Marskell – Drackir’s doubt, though text in MS Word is a long chain of string, office automation does still let us know line number. In fact I get the line number itself from another piece of code, like this:

Word.Revision rev = //SomeRevision
object lineNo = rev.Range.get_Information(Word.WdInformation.wdFirstCharacterLineNumber);

For instance say the Word file looks like this:

fix grammatical or spelling errors

clarify meaning without changing it correct minor mistakes add related resources or links
always respect the original author

Here there are 4 lines.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:11:41+00:00Added an answer on May 29, 2026 at 8:11 am

    Fortunately after some epic searching I got a solution.

        object file = Path.GetDirectoryName(Application.ExecutablePath) + @"\Answer.doc";
    
        Word.Application wordObject = new Word.ApplicationClass();
        wordObject.Visible = false;
    
        object nullobject = Missing.Value;
        Word.Document docs = wordObject.Documents.Open
            (ref file, ref nullobject, ref nullobject, ref nullobject,
            ref nullobject, ref nullobject, ref nullobject, ref nullobject,
            ref nullobject, ref nullobject, ref nullobject, ref nullobject,
            ref nullobject, ref nullobject, ref nullobject, ref nullobject);
    
        String strLine;
        bool bolEOF = false;
    
        docs.Characters[1].Select();
    
        int index = 0;
        do
        {
            object unit = Word.WdUnits.wdLine;
            object count = 1;
            wordObject.Selection.MoveEnd(ref unit, ref count);
    
            strLine = wordObject.Selection.Text;
            richTextBox1.Text += ++index + " - " + strLine + "\r\n"; //for our understanding
    
            object direction = Word.WdCollapseDirection.wdCollapseEnd;
            wordObject.Selection.Collapse(ref direction);
    
            if (wordObject.Selection.Bookmarks.Exists(@"\EndOfDoc"))
                bolEOF = true;
        } while (!bolEOF);
    
        docs.Close(ref nullobject, ref nullobject, ref nullobject);
        wordObject.Quit(ref nullobject, ref nullobject, ref nullobject);
        docs = null;
        wordObject = null;
    

    Here‘s the genius behind the code. Follow the link for some more explanation on how it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to get the first line of text from a UITextView. I
Possible Duplicate: Get all files from VSS for a given date? I need to
Using .get() is it possible to read only the first line of a .txt
Given an RFC822 message in Python 2.6, how can I get the right text/plain
Is it possible to extract a particular line from a file knowing its line
Is it possible to get the text of an OleDbCommand with all parameters replaced
I am reading one line of text from site. Here is example of what
Im using full text search to find rows that have a word near another
When I use putStrLn txt from several threads in Haskell, it's possible to get
I need to get text aligned right and left on the same line. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.