Provide required information needed to triage your issue
When fields are present, the values of the Word.Range.start and Word.Range.end properties do not correspond to the display text. It appears that hidden characters are affecting the value of these Word range properties.
Your Environment
- Platform [PC desktop, Mac, iOS, Office on the web]: PC desktop, Mac
- Host [Excel, Word, PowerPoint, etc.]: Word desktop
- Office version number: 16.111 (26062533)
- Operating System: Mac OS 26.5.1
Expected behavior
The values of the Word.Range.start and Word.Range.end properties are based on the displayed text.
Current behavior
The Word.Range.start and Word.Range.end properties are influenced by hidden characters.
Steps to reproduce
- Open the document Test.docx
- Run the following script in Script Lab -> https://gist.github.com/pdoyon-Druide/b85f0d37eb34c6d75efc0d002e1748c0
- Click the « Run » button.
Link to live example(s)
https://gist.github.com/pdoyon-Druide/b85f0d37eb34c6d75efc0d002e1748c0
Provide additional details
When the script runs, the cursor is positioned on the last character of the document.
The script execution results in the following:
- There is a field code with a length of 28 characters;
- The text contains 27 visible characters;
- The selection position is 58.
Therefore, the Word.Range.Start and Word.Range.End properties are determined by merging the display and hidden text.
Context
The Word.Range.Start and Word.Range.End properties should be based on the visible text, allowing for the easy identification of a range (such as the current selection) within a document.
Useful logs
test.docx
Thank you for taking the time to report an issue. Our triage team will respond to you in less than 72 hours. Normally, response time is <10 hours Monday through Friday. We do not triage on weekends.
Provide required information needed to triage your issue
When fields are present, the values of the Word.Range.start and Word.Range.end properties do not correspond to the display text. It appears that hidden characters are affecting the value of these Word range properties.
Your Environment
Expected behavior
The values of the Word.Range.start and Word.Range.end properties are based on the displayed text.
Current behavior
The Word.Range.start and Word.Range.end properties are influenced by hidden characters.
Steps to reproduce
Link to live example(s)
https://gist.github.com/pdoyon-Druide/b85f0d37eb34c6d75efc0d002e1748c0
Provide additional details
When the script runs, the cursor is positioned on the last character of the document.
The script execution results in the following:
Therefore, the Word.Range.Start and Word.Range.End properties are determined by merging the display and hidden text.
Context
The Word.Range.Start and Word.Range.End properties should be based on the visible text, allowing for the easy identification of a range (such as the current selection) within a document.
Useful logs
test.docx
Thank you for taking the time to report an issue. Our triage team will respond to you in less than 72 hours. Normally, response time is <10 hours Monday through Friday. We do not triage on weekends.