Programmatically reset ranges in Word documents
Use the SetRange method to resize an existing range in a Microsoft Office Word document.
Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Word. For more information, see Features available by Office application and project type.
To reset an existing range
Set an initial range starting with the first seven characters in the document.
The following code example can be used in a document-level customization.
The following code example can be used in a VSTO Add-in. This code uses the active document.
Use SetRange to start the range at the second sentence and end it at the end of the fifth sentence.
Document-Level Customization Example
To reset an existing range in a document-level customization
The following example shows the complete example for a document-level customization. To use this code, run it from the
ThisDocument
class in your project.
VSTO Add-in example
To reset an existing range in a VSTO Add-in
The following example shows the complete example for a VSTO Add-in. To use this code, run it from the
ThisAddIn
class in your project.
Related content
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for