Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send BACKSPACE keystroke in Word VBA

Tags:

ms-word

vba

I have made some code in Word VBA and at the end I need 1 backspace keytroke. How is this achievable?

like image 962
Morten Laustsen Avatar asked Jan 30 '13 13:01

Morten Laustsen


3 Answers

The simplest solution is just:

Selection.TypeBackspace
like image 182
CuberChase Avatar answered Oct 12 '22 12:10

CuberChase


The simple way to send a backspace (but not the most robust solution) :

SendKeys ("{BACKSPACE}")

A safer way to do this :

Selection.MoveLeft Extend:=wdExtend
Selection.Delete

If something is already selected, and you want to delete just the last character, preface the above by :

Selection.Collapse wdCollapseEnd

To go to the start of the current page :

ActiveDocument.GoTo(wdGoToPage, wdGoToRelative, 0).Select
like image 43
grahamj42 Avatar answered Oct 12 '22 13:10

grahamj42


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

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

This works for spaces too as they are counted with the len

like image 34
Daniel Avatar answered Oct 12 '22 13:10

Daniel