Skip to content

The Word.Range.start and Word.Range.end properties do not correspond to the displayed text. #6794

Description

@pdoyon-Druide

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

  1. Open the document Test.docx
  2. Run the following script in Script Lab -> https://gist.github.com/pdoyon-Druide/b85f0d37eb34c6d75efc0d002e1748c0
  3. 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

Image

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.

Metadata

Metadata

Labels

Area: WordIssue related to Word add-insNeeds: attention 👋Waiting on Microsoft to provide feedback

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions