Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'di Modul
- Option Explicit
- Public g_txtActiveTextbox As MSForms.TextBox
- Public Sub ShowDemo()
- UserForm1.Show
- End Sub
- Public Sub Textbox_Clear()
- g_txtActiveTextbox.Text = ""
- End Sub
- Public Sub Textbox_Select()
- g_txtActiveTextbox.SelStart = 0
- g_txtActiveTextbox.SelLength = Len(g_txtActiveTextbox.Text)
- End Sub
- Public Sub Textbox_Paste()
- g_txtActiveTextbox.Paste
- End Sub
- Public Sub Textbox_Copy()
- g_txtActiveTextbox.Copy
- End Sub
- Public Sub Textbox_Cut()
- g_txtActiveTextbox.Cut
- End Sub
- 'di userform
- Sub BuildTextboxMenu(X As Single, Y As Single)
- 'Hapus Menu existing
- On Error Resume Next
- 'CommandBars("MyTextboxMenu").Delete
- With CommandBars.Add(Name:="MyTextboxMenu", Position:=msoBarPopup)
- With .Controls.Add(Type:=msoControlButton)
- .OnAction = "Textbox_Cut"
- .Caption = "Cu&t"
- End With
- With .Controls.Add(Type:=msoControlButton)
- .OnAction = "Textbox_Copy"
- .Caption = "&Copy"
- End With
- With .Controls.Add(Type:=msoControlButton)
- .OnAction = "Textbox_Paste"
- .Caption = "&Paste"
- End With
- With .Controls.Add(Type:=msoControlButton)
- .OnAction = "Textbox_Clear"
- .Caption = "Cle&ar"
- End With
- With .Controls.Add(Type:=msoControlButton)
- .OnAction = "Textbox_Select"
- .Caption = "Select A&ll"
- .BeginGroup = True
- End With
- .ShowPopup
- End With
- CommandBars("MyTextboxMenu").Delete
- End Sub
- 'penggunaan
- Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
- If Button = xlSecondaryButton Then
- Set g_txtActiveTextbox = TextBox1
- BuildTextboxMenu X, Y
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement