Send BACKSPACE keypress in Word VBA

I did some code in Word VBA and at the end I need 1 reverse keytroke. How is this achievable?

+3


source to share


4 answers


Simple way to send backspace (but not the most reliable solution):

SendKeys ("{BACKSPACE}")

      

A safer way to do it:

Selection.MoveLeft Extend:=wdExtend
Selection.Delete

      



If something is already selected and you only want to remove the last character, imagine above:

Selection.Collapse wdCollapseEnd

      

To go to the top of the current page:

ActiveDocument.GoTo(wdGoToPage, wdGoToRelative, 0).Select

      

+2


source


Simplest solution:



Selection.TypeBackspace

      

+9


source


You can do it this way if your text is in a string or textbox:

dim strText as string
strText = yourdatasourcehere
strText = left(strText,len(strText) - 1)
youroutputsource = strText

      

This also works for spaces as they are counted using len

+1


source


Backspace is the character code (8). The sendkeys equivalent is {BACKSPACE}.

0


source







All Articles