none
How to get a page by page number from word.document RRS feed

  • Question

  • I have a word document containing several pages.

    How can I fetch/get/access a certain page from a word document by specifying its page number?

    I use microsoft.office.interop.word.document

    Isn't there any method like  word.document.pages.get(2)

    Thank you for any help. :-)


    • Edited by 0xTc0 Thursday, January 9, 2014 3:29 PM
    Thursday, January 9, 2014 3:29 PM

Answers

  • Hello 0xTc0,

    There is no such class in the Word object model. I'd recommend starting from the How to automate Microsoft Word to create a new document by using Visual C# article which explains the core Word objects you can operate.

    Note, you can use the Information property of the Selection and Range classes for getting the page number. For example:

    MsgBox "The selection is on page " & _ 
     Selection.Information(wdActiveEndPageNumber) & " of page " _ 
     & Selection.Information(wdNumberOfPagesInDocument)
    

    Thursday, January 9, 2014 4:03 PM
  • The Selection class provides the Move method which collapses the specified selection to its start or end position and then moves the collapsed object by the specified number of units. This method returns a Long value that represents the number of units by which the selection was moved, or it returns 0 (zero) if the move was unsuccessful.

    Also you can try to use the GoTo method of the Document class. It returns a Range object that represents the start position of the specified item, such as a page, bookmark, or field. If you want to move to the specified page, you need to pass the wdGoToPage value as the first parameter.

    Friday, January 10, 2014 9:57 AM

All replies

  • Hello 0xTc0,

    There is no such class in the Word object model. I'd recommend starting from the How to automate Microsoft Word to create a new document by using Visual C# article which explains the core Word objects you can operate.

    Note, you can use the Information property of the Selection and Range classes for getting the page number. For example:

    MsgBox "The selection is on page " & _ 
     Selection.Information(wdActiveEndPageNumber) & " of page " _ 
     & Selection.Information(wdNumberOfPagesInDocument)
    

    Thursday, January 9, 2014 4:03 PM
  • Thank you.

    I was afraid that there isn't any easy solution for that.

    So maybe I could shift the selection until the

    Selection.Information(wdActiveEndPageNumber)

    property equals the page number that I am looking for?

    Friday, January 10, 2014 8:13 AM
  • The Selection class provides the Move method which collapses the specified selection to its start or end position and then moves the collapsed object by the specified number of units. This method returns a Long value that represents the number of units by which the selection was moved, or it returns 0 (zero) if the move was unsuccessful.

    Also you can try to use the GoTo method of the Document class. It returns a Range object that represents the start position of the specified item, such as a page, bookmark, or field. If you want to move to the specified page, you need to pass the wdGoToPage value as the first parameter.

    Friday, January 10, 2014 9:57 AM