|
では、私からも一つ。
# ユーザーフォーム上、全てのTextBoxに
右クリックメニューを付けます。
' **********
' classモジュール(Class1)
Private WithEvents Txt As MSForms.TextBox
Private WithEvents mCopy As Office.CommandBarButton
Private WithEvents mCut As Office.CommandBarButton
Private WithEvents mPaste As Office.CommandBarButton
Public Sub Init(ByVal rhs As MSForms.TextBox)
Set Txt = rhs
End Sub
Private Sub mCopy_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
CancelDefault = True
Txt.Copy
End Sub
Private Sub mCut_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
CancelDefault = True
Txt.Cut
End Sub
Private Sub mPaste_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
CancelDefault = True
Txt.Paste
End Sub
Private Sub Txt_MouseUp(ByVal Button%, ByVal Shift%, ByVal X!, ByVal Y!)
If Button <> vbKeyRButton Then Exit Sub
With Application.CommandBars.Add(, msoBarPopup, , True)
Set mCopy = .Controls.Add(, 19)
Set mCut = .Controls.Add(, 21)
Set mPaste = .Controls.Add(, 22)
.ShowPopup
.Delete
End With
Set mCopy = Nothing
Set mCut = Nothing
Set mPaste = Nothing
End Sub
' **********
' Userformモジュール
Private col As Collection
Private Sub UserForm_Initialize()
Dim e As MSForms.Control
Dim cls As Class1
Set col = New Collection
For Each e In Controls
If TypeName(e) = "TextBox" Then
Set cls = New Class1
cls.Init e
col.Add cls
End If
Next
End Sub
|
|