Code:
Sub AddFirstList()
Dim strList As String
strList = Application.CommandBars.ActionControl.Caption
If Not strList Like "*...*" Then Exit Sub
ActiveCell = Left(strList, InStr(1, strList, ".", vbTextCompare) - 1)
End Sub[/highlight]
Bạn kích chuột hai lần lên ThisWorkbook trong cửa sổ VBAProject và nhập vào đoạn mã sau:
[highlight=VB]
Private Sub Workbook_SheetBeforeRightClick _
(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim cBut As CommandBarButton
Dim lListCount As Long
Dim lCount As Long
Dim strList As String
Dim MyList
On Error Resume Next
With Application
lListCount = .CustomListCount
For lCount = 1 To lListCount
MyList = .GetCustomListContents(lCount)
strList = .CommandBars("Cell").Controls(MyList(1) & "..." & _
MyList(UBound(MyList))).Caption
.CommandBars("Cell").Controls(strList).Delete
Set cBut = .CommandBars("Cell").Controls.Add(Temporary:=True)
With cBut
.Caption = MyList(1) & "..." & MyList(UBound(MyList))
.Style = msoButtonCaption
.OnAction = "AddFirstList"
End With
Next lCount
End With
On Error GoTo 0
End Sub
Đóng cửa sổ VBE và lưu bảng tính lại. Sau đó nhấp phải chuột vào một ô nào đó trên bảng tính, bạn sẽ thấy các Custom List dựng sẵn và do bạn tạo xuất hiện trong trình đơn ngữ cảnh.