问题
I have made some code in Word VBA and at the end I need 1 backspace keytroke. How is this achievable?
回答1:
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
回答2:
The simplest solution is just:
Selection.TypeBackspace
回答3:
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
回答4:
Backspace is character code (8). The sendkeys equivalent is {BACKSPACE}.
来源:https://stackoverflow.com/questions/14605653/send-backspace-keystroke-in-word-vba