Position cursor at start/end of Word document

后端 未结 9 788
误落风尘
误落风尘 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.

提交回复
热议问题