PrivateSub NewControl()Sub NewControl(obj As TextBox, Tar As TextBox, KeyCode AsInteger) Dim intPos AsInteger'光标位置 Dim strLeft AsString'光标左边的字符 Dim strRight AsString'光标右边的字符 If obj.Text =""Then Exit Sub EndIf intPos = obj.SelStart If intPos =0Then'最开头 If KeyCode = vbKeyLeft Then'按下左箭头 Tar.SetFocus Exit Sub EndIf EndIf If intPos =Len(obj.Text) Then'在最后 If KeyCode = vbKeyRight Then'按下右箭头 Tar.SetFocus Exit Sub EndIf EndIf If intPos >1Then strLeft =Mid(obj.Text, intPos -1, 1) EndIf If intPos <Len(obj.Text) Then strRight =Mid(obj.Text, intPos +1, 1) EndIf If strLeft =Chr(13) Then'左边是换行,表示光标在行首 If KeyCode = vbKeyLeft Then'这时按左箭头,则切换 KeyCode =0 Tar.SetFocus Exit Sub EndIf EndIf If strRight =Chr(13) Then'右边是回车,表示光标在行尾 If KeyCode = vbKeyRight Then'这时按右箭头,则切换 KeyCode =0 Tar.SetFocus Exit Sub EndIf EndIf End Sub