Mình muốn dùng TextBox vì lý do:
Chỉ cho hiện tên của người đang mở File Và họ chỉ có quyền mở được cái Frame của họ thôi.
OK, vậy thì làm theo kiểu của bạn vậy!
Toàn bộ code trong Form sẽ như sau:
[GPECODE=vb]Private OldFrame As String, FrameArr(1 To 9)
Private Sub UserForm_Initialize()
Dim i As Byte
For i = 1 To 9
Me("Frame" & i).Caption = Sheets("Sheet1").Range("N" & i)
FrameArr(i) = Me("Frame" & i).Name
Next
TextBox1 = Sheets("Sheet1").Range("A1")
End Sub
Private Sub CommandButton1_Click()
With TextBox1
If Trim(.Text) = "" Then
MsgBox "Please insert your name here!"
.SetFocus
Else
Dim FindRange As Range
Set FindRange = Range("N1:N9").Find(.Text, LookIn:=xlValues, LookAt:=xlWhole)
If FindRange Is Nothing Then
MsgBox "Your name is incorrect!"
If OldFrame <> "" Then Me(OldFrame).Visible = False
OldFrame = ""
.SetFocus: .SelStart = 0: .SelLength = Len(.Text)
Else
With Me(FrameArr(FindRange.Row))
If .Name <> OldFrame Then
If OldFrame <> "" Then Me(OldFrame).Visible = False
.Left = Frame1.Left
.Top = Frame1.Top
.Visible = True
OldFrame = .Name
End If
End With
End If
End If
End With
End Sub
[/GPECODE]