Word VBA: Range.Characters.First.Delete delets 2 characters if the second character is a space

Viewed 36

I want to delete a fixed number of characters of a paragraph in MS Word. I came across a situation where the paragraph starts with some character as the first character and a space as the second character. When I select the paragraph range and execute Range.Characters.First.Delete the second character (space) also gets deleted instead of only the first one.

Does anyone know why this behaviour is taking place?

3 Answers

You could use:

.Range.Characters.First.Text = vbNullstring

or:

.Range.Words.First.Text = " "

You need to investigate the Advanced Options of Word File.Options.Advanced then scroll down to cut, copy and paste and open the settings for Smart Cut and Paste. Experiment with the options therein.

You could use:

Selection.Range.Delete Unit:=wdCharacter, Count:=1
Related