我想在用户输入时更改Excel用户窗体中文本框的填充颜色,或者按Enter键插入换行符。如何在VBA中测试换行的存在?
由于
答案 0 :(得分:1)
Private Sub TextBox1_BeforeDropOrPaste(ByVal Cancel As MSForms.ReturnBoolean, ByVal Action As MSForms.fmAction, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
If Action = fmActionPaste Then
TextBox1.BackColor = vbGreen
On Error Resume Next
Data.GetFromClipboard
TextBox1.Text = TextBox1.Text & vbCrLf & Data.GetText
On Error GoTo 0
End If
End Sub
Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
TextBox1.BackColor = vbGreen
TextBox1.Text = TextBox1.Text & vbCrLf
End If
End Sub