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

Time:09-15

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?

CodePudding user response:

You could use:

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

CodePudding user response:

You could use:

.Range.Characters.First.Text = vbNullstring

or:

.Range.Words.First.Text = " "
  • Related