Position cursor at start/end of Word document

后端 未结 9 770
误落风尘
误落风尘 2020-12-11 16:39

We are manipulating our Word 2007 documents from .Net using Word Interop. Mostly doing stuff with fields as in:

For Each f In d.Fields
    f.Select()
    //d         


        
相关标签:
9条回答
  • 2020-12-11 17:08

    The easiest way to figure out an outline for the actual code is to record a macro in Word for that specific action. Then you can modify the generated code to suit different syntax(s) of VB, VB.NET, C# etc.

    The code snippet below demonstrates the usage for a VB.NET application:

    Imports wordNmSpace = Microsoft.Office.Interop.Word
    ' Create an object for the application instance
    objWord = CreateObject("Word.Application")
    
    ' Create a reference of the selection object within Word
    objSelection = objWord.Selection
    
    ' Now comes the part where you move selection position to the end of document
    objSelection.endof(wordNmSpace.WdUnits.wdStory, wordNmSpace.WdMovementType.wdMove)
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-11 17:10

    You can use the predefined bookmark:

    EndOfDoc oDoc.Bookmarks.Item("\endofdoc").Range
    

    Other predefined bookmarks:

    ActiveDocument.Bookmarks("\Para").Copy "currpara"
    

    https://msdn.microsoft.com/en-us/VBA/Word-VBA/articles/predefined-bookmarks

    0 讨论(0)
  • 2020-12-11 17:14

    for net office:

    mydoc.Range(GlobalClass.mydoc.Content.End-1 , mydoc.Content.End - 1).Select();
    
    0 讨论(0)
提交回复
热议问题