Send BACKSPACE keystroke in Word VBA

陌路散爱 提交于 2020-01-02 08:28:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!