0
votes

I'm working on a vba macro in word that trims given characters from the end of a range. Whenever I have it try to delete the Negative Acknowledgement Character I get the error Cannot edit Range. The range has the size of exactly 1 and contains only the character with ASCII value 21.

What is the purpose of this character in a MS Word doc, why can't I delete it, and how could I delete it? I need to delete the character because whenever I insert text before or after it my inserted text becomes "Error!".

1

1 Answers

0
votes

The trick is to select the range and then use Selection.Delete like so:

Dim rng As Range
Set rng = ActiveDocument.Range(i, i + 1) 
Debug.Print Asc(rng.text) ' 21
rng.Select
Selection.Delete

Why does Selection.Delete work and not Range.Delete? IDK. I expect Selection be nothing more than the alias to the selected range but its not so. Selection is it's own class with it's own doc page and everything.