|
Vicel 发表于 2015-3-8 20:52
增加词条删除功能
回看此帖,感觉蛮实用的,也挺强大的。
但由于我的电脑无法安装ListView控件,故只好用ListBox控件代替,相应地,第3个窗体的代码更改如下:- Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
- Me.TextBox3.Visible = False
- Me.CommandButton1.Visible = False
- If Me.ToggleButton1.Caption = "切换/英" Then
- Me.Label1.Caption = "关键字词@中文查询"
- Me.TextBox2.SetFocus
- Else
- Me.Label1.Caption = "关键字词@英文查询"
- Me.TextBox1.SetFocus
- End If
- End Sub
- Private Sub Label2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
- If Me.TextBox1.Visible = True Then
- c = 1
- ElseIf Me.TextBox2.Visible = True Then
- c = 2
- End If
- With Me.Controls("Textbox" & c)
- If .Text <> "" Then
- .SelStart = 0
- .SelLength = Len(.Text)
- End If
- .SetFocus
- End With
- End Sub
- Private Sub ListBox1_Click()
- Me.TextBox3.Visible = True
- Me.CommandButton1.Visible = True
- Me.Label1.Caption = "关键词@" & IIf(c = 1, "英", "中") & "文查询"
- TextBox3.Text = ListBox1.List(ListBox1.ListIndex, IIf(c = 1, 2, 1))
- End Sub
- Sub TextBox_Change(c)
- Str = Trim(Me.Controls("TextBox" & c).Text)
-
- Dim arr, cel, m, n
- ListBox1.Clear
- ReDim arr(1 To 100, 1 To 3)
- For Each cel In Sheets("单词表").Range("a1:a100").Offset(, c)
- If cel.Text Like "*" & Str & "*" Then
- m = m + 1
- For n = 1 To 3
- arr(m, n) = cel.Offset(, n - 1 - c).Text
- Next n
- End If
- Next
- ListBox1.List = arr
- End Sub
- Private Sub TextBox1_Change()
- c = 1
- TextBox_Change (c)
- End Sub
- Private Sub TextBox2_Change()
- c = 2
- TextBox_Change (c)
- End Sub
- Private Sub TextBox3_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
- With Me.TextBox3
- If .Text = "" Then Exit Sub
- .SelStart = 0
- .SelLength = Len(.Text)
- .SetFocus
- .Copy
- End With
- End Sub
- Private Sub ToggleButton1_Click()
- temp = Me.TextBox2.Visible
- Me.TextBox2.Visible = Me.TextBox1.Visible
- Me.TextBox1.Visible = temp
- ar = Sheets("单词表").[A1].CurrentRegion
- Select Case Me.ToggleButton1.Value
- Case False
- Me.ToggleButton1.Caption = "切换/中"
- Me.Label1.Caption = "关键字词@英文查询"
- Me.Label1.ForeColor = &H8000&
- ListBox1.ColumnWidths = "0,60,0"
- Case True
- Me.ToggleButton1.Caption = "切换/英"
- Me.Label1.Caption = "关键字词@中文查询"
- Me.Label1.ForeColor = &HC000C0
- ListBox1.ColumnWidths = "0,0,60"
- End Select
- With Me.Controls("Textbox" & Me.ToggleButton1.Value ^ 2 + 1)
- .Text = " "
- .Text = ""
- .SetFocus
- End With
- End Sub
- Private Sub UserForm_Activate()
- If Me.TextBox1.Visible = True Then TextBox_Change (1)
- If Me.TextBox2.Visible = True Then TextBox_Change (2)
- End Sub
- Private Sub UserForm_Initialize()
- ar = Sheets("单词表").[A1].CurrentRegion
- ListBox1.List = ar
- End Sub
- Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
- If CloseMode = 0 Then
- Cancel = 1
- Unload Me
- Me.Hide
- UserForm1.Show
- End If
- End Sub
复制代码 |
|